Commit 42adfbff authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Remove FindEntryByPathAndRunSync() from GDataWapiFeedLoader.

GDataWapiFeedLoader sould only focus on loading the feeds, without
doing the extra step to find an entry.

The number of callers of FindEntryByPathAndRunSync() is reduced from 4 to 2.

Along the way, make LoadDocumentFeedCallback parameter mandatory for
LoadFromServer() and friends. Looking at callers, it's safe to make this
mandatory.

BUG=141196, 126634
TEST=file manager works as before (loading from the server and from the cache)

Review URL: https://chromiumcodereview.appspot.com/10824303

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151654 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d2c2c1c
......@@ -579,7 +579,6 @@ void GDataFileSystem::CheckForUpdates() {
feed_loader_->ReloadFromServerIfNeeded(
initial_origin,
directory_service_->largest_changestamp(),
directory_service_->root()->GetFilePath(),
base::Bind(&GDataFileSystem::OnUpdateChecked,
ui_weak_ptr_,
initial_origin));
......@@ -587,13 +586,11 @@ void GDataFileSystem::CheckForUpdates() {
}
void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin,
GDataFileError error,
GDataEntry* /* entry */) {
GDataFileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error != GDATA_FILE_OK) {
if (error != GDATA_FILE_OK)
directory_service_->set_origin(initial_origin);
}
}
GDataFileSystem::~GDataFileSystem() {
......@@ -712,10 +709,10 @@ void GDataFileSystem::FindEntryByPathAsyncOnUIThread(
directory_service_->set_origin(INITIALIZING);
feed_loader_->LoadFromCache(
true, // should_load_from_server
search_file_path,
// This is the initial load, hence we'll notify when it's done.
base::Bind(&GDataFileSystem::RunAndNotifyInitialLoadFinished,
base::Bind(&GDataFileSystem::FindAndNotifyInitialLoadFinished,
ui_weak_ptr_,
search_file_path,
callback));
return;
}
......@@ -2030,25 +2027,25 @@ void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo(
feed_loader_->LoadFromServer(
directory_service_->origin(),
0, // Not delta feed.
0, // Not used.
0, // start_changestamp - Not a delta feed.
0, // root_feed_changestamp - Not used.
true, // multiple feeds
file_path,
std::string(), // No search query
GURL(), /* feed not explicitly set */
entry_proto->resource_id(),
FindEntryCallback(), // Not used.
GURL(), // feed_to_load - Feed not explicitly set
entry_proto->resource_id(), // Load the feed for this directory.
FileOperationCallback(), // load_finished_callback.
base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh,
ui_weak_ptr_));
ui_weak_ptr_,
file_path));
}
void GDataFileSystem::OnRequestDirectoryRefresh(
const FilePath& directory_path,
GetDocumentsParams* params,
GDataFileError error) {
DCHECK(params);
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const FilePath& directory_path = params->search_file_path;
if (error != GDATA_FILE_OK) {
LOG(ERROR) << "Failed to refresh directory: " << directory_path.value()
<< ": " << error;
......@@ -2448,11 +2445,10 @@ void GDataFileSystem::SearchAsyncOnUIThread(
false, // Stop fetching search results after first feed
// chunk to avoid displaying huge number of search
// results (especially since we don't cache them).
FilePath(), // Not used.
search_query,
next_feed,
std::string(), // No directory resource ID.
FindEntryCallback(), // Not used.
FileOperationCallback(), // Not used.
base::Bind(&GDataFileSystem::OnSearch, ui_weak_ptr_, callback));
}
......@@ -2482,9 +2478,7 @@ void GDataFileSystem::LoadRootFeedFromCacheForTesting() {
feed_loader_->LoadFromCache(
false, // should_load_from_server.
// search_path doesn't matter if FindEntryCallback parameter is null .
FilePath(),
FindEntryCallback());
FileOperationCallback());
}
GDataFileError GDataFileSystem::UpdateFromFeedForTesting(
......@@ -2847,14 +2841,15 @@ void GDataFileSystem::NotifyFileSystemToBeUnmounted() {
OnFileSystemBeingUnmounted());
}
void GDataFileSystem::RunAndNotifyInitialLoadFinished(
void GDataFileSystem::FindAndNotifyInitialLoadFinished(
const FilePath& search_file_path,
const FindEntryCallback& callback,
GDataFileError error,
GDataEntry* entry) {
GDataFileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
callback.Run(error, entry);
// TODO(satorux): Remove this: crbug.com/141196.
directory_service_->FindEntryByPathAndRunSync(search_file_path, callback);
DVLOG(1) << "RunAndNotifyInitialLoadFinished";
......
......@@ -556,14 +556,14 @@ class GDataFileSystem : public GDataFileSystemInterface,
// reloaded, and in case of failure, restores the content origin of the root
// directory.
void OnUpdateChecked(ContentOrigin initial_origin,
GDataFileError error,
GDataEntry* entry);
GDataFileError error);
// Runs the callback and notifies that the initial load is finished.
// Finds the entry for |search_file_path| synchronously and runs the
// callback, then notifies that the initial load is finished.
// |callback| must not be null.
void RunAndNotifyInitialLoadFinished(const FindEntryCallback& callback,
GDataFileError error,
GDataEntry* entry);
void FindAndNotifyInitialLoadFinished(const FilePath& search_file_path,
const FindEntryCallback& callback,
GDataFileError error);
// Helper function that completes bookkeeping tasks related to
// completed file transfer.
......@@ -739,7 +739,8 @@ class GDataFileSystem : public GDataFileSystemInterface,
const FilePath& file_path,
const ReadDirectoryWithSettingCallback& callback);
void RequestDirectoryRefreshOnUIThread(const FilePath& file_path);
void OnRequestDirectoryRefresh(GetDocumentsParams* params,
void OnRequestDirectoryRefresh(const FilePath& directory_path,
GetDocumentsParams* params,
GDataFileError error);
void GetAvailableSpaceOnUIThread(const GetAvailableSpaceCallback& callback);
void AddUploadedFileOnUIThread(UploadMode upload_mode,
......
......@@ -24,10 +24,9 @@ struct GetDocumentsParams {
int64 root_feed_changestamp,
std::vector<DocumentFeed*>* feed_list,
bool should_fetch_multiple_feeds,
const FilePath& search_file_path,
const std::string& search_query,
const std::string& directory_resource_id,
const FindEntryCallback& callback,
const FileOperationCallback& callback,
GetDocumentsUiState* ui_state);
~GetDocumentsParams();
......@@ -41,29 +40,26 @@ struct GetDocumentsParams {
// Should we stop after getting first feed chunk, even if there is more
// data.
bool should_fetch_multiple_feeds;
FilePath search_file_path;
std::string search_query;
std::string directory_resource_id;
FindEntryCallback callback;
FileOperationCallback callback;
scoped_ptr<GetDocumentsUiState> ui_state;
};
// Defines set of parameters sent to callback OnProtoLoaded().
struct LoadRootFeedParams {
LoadRootFeedParams(
FilePath search_file_path,
bool should_load_from_server,
const FindEntryCallback& callback);
const FileOperationCallback& callback);
~LoadRootFeedParams();
FilePath search_file_path;
bool should_load_from_server;
std::string proto;
GDataFileError load_error;
base::Time last_modified;
// Time when filesystem began to be loaded from disk.
base::Time load_start_time;
const FindEntryCallback callback;
const FileOperationCallback callback;
};
// Callback run as a response to LoadFromServer.
......@@ -107,39 +103,46 @@ class GDataWapiFeedLoader {
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
// Starts root feed load from the cache. If successful, it will try to find
// the file upon retrieval completion. In addition to that, it will
// initiate retrieval of the root feed from the server unless
// Starts root feed load from the cache. If successful, runs |callback| to
// tell the caller that the loading was successful.
//
// Then, it will initiate retrieval of the root feed from the server unless
// |should_load_from_server| is set to false. |should_load_from_server| is
// false only for testing.
// false only for testing. If loading from the server is successful, runs
// |callback| if it was not previously run (i.e. loading from the cache was
// successful).
//
// |callback| may be null.
void LoadFromCache(bool should_load_from_server,
const FilePath& search_file_path,
const FindEntryCallback& callback);
const FileOperationCallback& callback);
// Starts root feed load from the server. Value of |start_changestamp|
// determines the type of feed to load - 0 means root feed, every other
// value would trigger delta feed.
// In the case of loading the root feed we use |root_feed_changestamp| as its
// initial changestamp value since it does not come with that info.
// When done |load_feed_callback| is invoked.
// |entry_found_callback| is used only when this is invoked while searching
// for file info, and is used in |load_feed_callback|. If successful, it will
// try to find the file upon retrieval completion.
//
// When all feeds are loaded, |feed_load_callback| is invoked with the
// retrieved feeds. Then |load_finished_callback| is invoked with the error
// code.
//
// |should_fetch_multiple_feeds| is true iff don't want to stop feed loading
// after we retrieve first feed chunk.
// If invoked as a part of content search, query will be set in
// |search_query|.
// If |feed_to_load| is set, this is feed url that will be used to load feed.
//
// |load_finished_callback| may be null.
// |feed_load_callback| must not be null.
void LoadFromServer(
ContentOrigin initial_origin,
int64 start_changestamp,
int64 root_feed_changestamp,
bool should_fetch_multiple_feeds,
const FilePath& search_file_path,
const std::string& search_query,
const GURL& feed_to_load,
const std::string& directory_resource_id,
const FindEntryCallback& entry_found_callback,
const FileOperationCallback& load_finished_callback,
const LoadDocumentFeedCallback& feed_load_callback);
// Retrieves account metadata and determines from the last change timestamp
......@@ -147,8 +150,7 @@ class GDataWapiFeedLoader {
void ReloadFromServerIfNeeded(
ContentOrigin initial_origin,
int64 local_changestamp,
const FilePath& search_file_path,
const FindEntryCallback& callback);
const FileOperationCallback& callback);
// Updates whole directory structure feeds collected in |feed_list|.
// On success, returns PLATFORM_FILE_OK. Record file statistics as UMA
......@@ -176,8 +178,7 @@ class GDataWapiFeedLoader {
void OnGetAccountMetadata(
ContentOrigin initial_origin,
int64 local_changestamp,
const FilePath& search_file_path,
const FindEntryCallback& callback,
const FileOperationCallback& callback,
GDataErrorCode status,
scoped_ptr<base::Value> feed_data);
......@@ -188,8 +189,7 @@ class GDataWapiFeedLoader {
void OnGetAboutResource(
ContentOrigin initial_origin,
int64 local_changestamp,
const FilePath& search_file_path,
const FindEntryCallback& callback,
const FileOperationCallback& callback,
GDataErrorCode status,
scoped_ptr<base::Value> feed_data);
......@@ -203,6 +203,7 @@ class GDataWapiFeedLoader {
// Callback for handling response from |GDataDocumentsService::GetDocuments|.
// Invokes |callback| when done.
// |callback| must not be null.
void OnGetDocuments(
ContentOrigin initial_origin,
const LoadDocumentFeedCallback& callback,
......@@ -213,6 +214,7 @@ class GDataWapiFeedLoader {
// Callback for handling response from |GDataDocumentsService::GetChanglist|.
// Invokes |callback| when done.
// |callback| must not be null.
void OnGetChangelist(ContentOrigin initial_origin,
const LoadDocumentFeedCallback& callback,
GetDocumentsParams* params,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment