Index: chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
index 569c081de340a15781def5bd99eddd7ec5b971fb..0309486d56c5aa5c73038fb241465ddaa6bd8bdc 100644 |
--- a/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
+++ b/chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc |
@@ -139,11 +139,9 @@ bool UseLevelDB() { |
} // namespace |
LoadRootFeedParams::LoadRootFeedParams( |
- FilePath search_file_path, |
bool should_load_from_server, |
- const FindEntryCallback& callback) |
- : search_file_path(search_file_path), |
- should_load_from_server(should_load_from_server), |
+ const FileOperationCallback& callback) |
+ : should_load_from_server(should_load_from_server), |
load_error(GDATA_FILE_OK), |
load_start_time(base::Time::Now()), |
callback(callback) { |
@@ -157,16 +155,14 @@ GetDocumentsParams::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) |
: start_changestamp(start_changestamp), |
root_feed_changestamp(root_feed_changestamp), |
feed_list(feed_list), |
should_fetch_multiple_feeds(should_fetch_multiple_feeds), |
- search_file_path(search_file_path), |
search_query(search_query), |
directory_resource_id(directory_resource_id), |
callback(callback), |
@@ -237,8 +233,7 @@ void GDataWapiFeedLoader::RemoveObserver(Observer* observer) { |
void GDataWapiFeedLoader::ReloadFromServerIfNeeded( |
ContentOrigin initial_origin, |
int64 local_changestamp, |
- const FilePath& search_file_path, |
- const FindEntryCallback& callback) { |
+ const FileOperationCallback& callback) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DVLOG(1) << "ReloadFeedFromServerIfNeeded local_changestamp=" |
@@ -252,7 +247,6 @@ void GDataWapiFeedLoader::ReloadFromServerIfNeeded( |
weak_ptr_factory_.GetWeakPtr(), |
initial_origin, |
local_changestamp, |
- search_file_path, |
callback)); |
return; |
} |
@@ -262,15 +256,13 @@ void GDataWapiFeedLoader::ReloadFromServerIfNeeded( |
weak_ptr_factory_.GetWeakPtr(), |
initial_origin, |
local_changestamp, |
- search_file_path, |
callback)); |
} |
void GDataWapiFeedLoader::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) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -281,7 +273,6 @@ void GDataWapiFeedLoader::OnGetAccountMetadata( |
LoadFromServer(initial_origin, |
local_changestamp + 1, 0, |
true, /* should_fetch_multiple_feeds */ |
- search_file_path, |
std::string() /* no search query */, |
GURL(), /* feed not explicitly set */ |
std::string() /* no directory resource ID */, |
@@ -311,7 +302,6 @@ void GDataWapiFeedLoader::OnGetAccountMetadata( |
LoadFromServer(initial_origin, |
local_changestamp + 1, 0, |
true, /* should_fetch_multiple_feeds */ |
- search_file_path, |
std::string() /* no search query */, |
GURL(), /* feed not explicitly set */ |
std::string() /* no directory resource ID */, |
@@ -338,12 +328,10 @@ void GDataWapiFeedLoader::OnGetAccountMetadata( |
changes_detected = false; |
} |
- // No changes detected, continue with search as planned. |
+ // No changes detected, tell the client that the loading was successful. |
if (!changes_detected) { |
- if (!callback.is_null()) { |
- directory_service_->FindEntryByPathAndRunSync(search_file_path, |
- callback); |
- } |
+ if (!callback.is_null()) |
+ callback.Run(GDATA_FILE_OK); |
return; |
} |
@@ -352,7 +340,6 @@ void GDataWapiFeedLoader::OnGetAccountMetadata( |
local_changestamp > 0 ? local_changestamp + 1 : 0, |
account_metadata->largest_changestamp(), |
true, /* should_fetch_multiple_feeds */ |
- search_file_path, |
std::string() /* no search query */, |
GURL(), /* feed not explicitly set */ |
std::string() /* no directory resource ID */, |
@@ -364,8 +351,7 @@ void GDataWapiFeedLoader::OnGetAccountMetadata( |
void GDataWapiFeedLoader::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) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -376,7 +362,6 @@ void GDataWapiFeedLoader::OnGetAboutResource( |
LoadFromServer(initial_origin, |
local_changestamp + 1, 0, |
true, /* should_fetch_multiple_feeds */ |
- search_file_path, |
std::string() /* no search query */, |
GURL(), /* feed not explicitly set */ |
std::string() /* no directory resource ID */, |
@@ -394,7 +379,6 @@ void GDataWapiFeedLoader::OnGetAboutResource( |
LoadFromServer(initial_origin, |
local_changestamp + 1, 0, |
true, /* should_fetch_multiple_feeds */ |
- search_file_path, |
std::string() /* no search query */, |
GURL(), /* feed not explicitly set */ |
std::string() /* no directory resource ID */, |
@@ -422,12 +406,10 @@ void GDataWapiFeedLoader::OnGetAboutResource( |
changes_detected = false; |
} |
- // No changes detected, continue with search as planned. |
+ // No changes detected, tell the client that the loading was successful. |
if (!changes_detected) { |
- if (!callback.is_null()) { |
- directory_service_->FindEntryByPathAndRunSync(search_file_path, |
- callback); |
- } |
+ if (!callback.is_null()) |
+ callback.Run(GDATA_FILE_OK); |
return; |
} |
@@ -436,7 +418,6 @@ void GDataWapiFeedLoader::OnGetAboutResource( |
local_changestamp > 0 ? local_changestamp + 1 : 0, |
largest_changestamp, |
true, /* should_fetch_multiple_feeds */ |
- search_file_path, |
std::string() /* no search query */, |
GURL(), /* feed not explicitly set */ |
std::string() /* no directory resource ID */, |
@@ -451,13 +432,13 @@ void GDataWapiFeedLoader::LoadFromServer( |
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) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ DCHECK(!feed_load_callback.is_null()); |
// |feed_list| will contain the list of all collected feed updates that |
// we will receive through calls of DocumentsService::GetDocuments(). |
@@ -478,10 +459,9 @@ void GDataWapiFeedLoader::LoadFromServer( |
root_feed_changestamp, |
feed_list.release(), |
should_fetch_multiple_feeds, |
- search_file_path, |
search_query, |
directory_resource_id, |
- entry_found_callback, |
+ load_finished_callback, |
NULL)), |
start_time)); |
return; |
@@ -500,10 +480,9 @@ void GDataWapiFeedLoader::LoadFromServer( |
root_feed_changestamp, |
feed_list.release(), |
should_fetch_multiple_feeds, |
- search_file_path, |
search_query, |
directory_resource_id, |
- entry_found_callback, |
+ load_finished_callback, |
NULL)), |
start_time)); |
} |
@@ -514,7 +493,7 @@ void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params, |
if (error != GDATA_FILE_OK) { |
if (!params->callback.is_null()) |
- params->callback.Run(error, NULL); |
+ params->callback.Run(error); |
return; |
} |
@@ -524,7 +503,7 @@ void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params, |
if (error != GDATA_FILE_OK) { |
if (!params->callback.is_null()) |
- params->callback.Run(error, NULL); |
+ params->callback.Run(error); |
return; |
} |
@@ -532,11 +511,9 @@ void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params, |
// Save file system metadata to disk. |
SaveFileSystem(); |
- // If we had someone to report this too, then this retrieval was done in a |
- // context of search... so continue search. |
+ // Tell the client that the loading was successful. |
if (!params->callback.is_null()) { |
- directory_service_->FindEntryByPathAndRunSync(params->search_file_path, |
- params->callback); |
+ params->callback.Run(GDATA_FILE_OK); |
} |
FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); |
@@ -550,6 +527,7 @@ void GDataWapiFeedLoader::OnGetDocuments( |
GDataErrorCode status, |
scoped_ptr<base::Value> data) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ DCHECK(!callback.is_null()); |
if (params->feed_list->empty()) { |
UMA_HISTOGRAM_TIMES("Gdata.InitialFeedLoadTime", |
@@ -564,19 +542,14 @@ void GDataWapiFeedLoader::OnGetDocuments( |
if (error != GDATA_FILE_OK) { |
directory_service_->set_origin(initial_origin); |
- |
- if (!callback.is_null()) |
- callback.Run(params, error); |
- |
+ callback.Run(params, error); |
return; |
} |
GURL next_feed_url; |
scoped_ptr<DocumentFeed> current_feed(DocumentFeed::ExtractAndParse(*data)); |
if (!current_feed.get()) { |
- if (!callback.is_null()) { |
- callback.Run(params, GDATA_FILE_ERROR_FAILED); |
- } |
+ callback.Run(params, GDATA_FILE_ERROR_FAILED); |
return; |
} |
const bool has_next_feed_url = current_feed->GetNextFeedURL(&next_feed_url); |
@@ -642,7 +615,6 @@ void GDataWapiFeedLoader::OnGetDocuments( |
params->root_feed_changestamp, |
params->feed_list.release(), |
params->should_fetch_multiple_feeds, |
- params->search_file_path, |
params->search_query, |
params->directory_resource_id, |
params->callback, |
@@ -651,15 +623,15 @@ void GDataWapiFeedLoader::OnGetDocuments( |
return; |
} |
- // Notify the observers that a document feed is fetched. |
+ // Notify the observers that all document feeds are fetched. |
FOR_EACH_OBSERVER(Observer, observers_, |
OnDocumentFeedFetched(num_accumulated_entries)); |
UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime", |
base::TimeTicks::Now() - start_time); |
- if (!callback.is_null()) |
- callback.Run(params, error); |
+ // Run the callback so the client can process the retrieved feeds. |
+ callback.Run(params, error); |
} |
void GDataWapiFeedLoader::OnGetChangelist( |
@@ -670,6 +642,7 @@ void GDataWapiFeedLoader::OnGetChangelist( |
GDataErrorCode status, |
scoped_ptr<base::Value> data) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ DCHECK(!callback.is_null()); |
if (params->feed_list->empty()) { |
UMA_HISTOGRAM_TIMES("Drive.InitialFeedLoadTime", |
@@ -684,19 +657,14 @@ void GDataWapiFeedLoader::OnGetChangelist( |
if (error != GDATA_FILE_OK) { |
directory_service_->set_origin(initial_origin); |
- |
- if (!callback.is_null()) |
- callback.Run(params, error); |
- |
+ callback.Run(params, error); |
return; |
} |
GURL next_feed_url; |
scoped_ptr<ChangeList> current_feed(ChangeList::CreateFrom(*data)); |
if (!current_feed.get()) { |
- if (!callback.is_null()) { |
- callback.Run(params, GDATA_FILE_ERROR_FAILED); |
- } |
+ callback.Run(params, GDATA_FILE_ERROR_FAILED); |
return; |
} |
const bool has_next_feed = !current_feed->next_page_token().empty(); |
@@ -762,7 +730,6 @@ void GDataWapiFeedLoader::OnGetChangelist( |
params->root_feed_changestamp, |
params->feed_list.release(), |
params->should_fetch_multiple_feeds, |
- params->search_file_path, |
params->search_query, |
params->directory_resource_id, |
params->callback, |
@@ -771,15 +738,15 @@ void GDataWapiFeedLoader::OnGetChangelist( |
return; |
} |
- // Notify the observers that a document feed is fetched. |
+ // Notify the observers that all document feeds are fetched. |
FOR_EACH_OBSERVER(Observer, observers_, |
OnDocumentFeedFetched(num_accumulated_entries)); |
UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime", |
base::TimeTicks::Now() - start_time); |
- if (!callback.is_null()) |
- callback.Run(params, error); |
+ // Run the callback so the client can process the retrieved feeds. |
+ callback.Run(params, error); |
} |
void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( |
@@ -821,12 +788,10 @@ void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( |
void GDataWapiFeedLoader::LoadFromCache( |
bool should_load_from_server, |
- const FilePath& search_file_path, |
- const FindEntryCallback& callback) { |
+ const FileOperationCallback& callback) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, |
- should_load_from_server, |
+ LoadRootFeedParams* params = new LoadRootFeedParams(should_load_from_server, |
callback); |
FilePath path = cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META); |
if (UseLevelDB()) { |
@@ -878,13 +843,14 @@ void GDataWapiFeedLoader::ContinueWithInitializedDirectoryService( |
<< (base::Time::Now() - params->load_start_time).InMilliseconds() |
<< " milliseconds"; |
- FindEntryCallback callback = params->callback; |
- // If we got feed content from cache, try search over it. |
+ // TODO(satorux): Simplify the callback handling. crbug.com/142799 |
+ FileOperationCallback callback = params->callback; |
+ // If we got feed content from cache, tell the client that the loading was |
+ // successful. |
if (error == GDATA_FILE_OK && !callback.is_null()) { |
- // Continue file content search operation if the delegate hasn't terminated |
- // this search branch already. |
- directory_service_->FindEntryByPathAndRunSync(params->search_file_path, |
- callback); |
+ callback.Run(GDATA_FILE_OK); |
+ // Reset the callback so we don't run the same callback once |
+ // ReloadFeedFromServerIfNeeded() is complete. |
callback.Reset(); |
} |
@@ -909,7 +875,6 @@ void GDataWapiFeedLoader::ContinueWithInitializedDirectoryService( |
// content without continuing search upon operation completion. |
ReloadFromServerIfNeeded(initial_origin, |
directory_service_->largest_changestamp(), |
- params->search_file_path, |
callback); |
} |