Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc

Issue 10836285: Refactor GDataWapiFeedLoader::LoadFromServer() parameters (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make struct and LoadFromServer() private. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h" 5 #include "chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 131 }
132 } 132 }
133 133
134 bool UseLevelDB() { 134 bool UseLevelDB() {
135 return CommandLine::ForCurrentProcess()->HasSwitch( 135 return CommandLine::ForCurrentProcess()->HasSwitch(
136 switches::kUseLevelDBForGData); 136 switches::kUseLevelDBForGData);
137 } 137 }
138 138
139 } // namespace 139 } // namespace
140 140
141 LoadRootFeedParams::LoadRootFeedParams(
142 bool should_load_from_server,
143 const FileOperationCallback& callback)
144 : should_load_from_server(should_load_from_server),
145 load_error(GDATA_FILE_OK),
146 load_start_time(base::Time::Now()),
147 callback(callback) {
148 }
149
150 LoadRootFeedParams::~LoadRootFeedParams() {
151 }
152
153 GetDocumentsParams::GetDocumentsParams( 141 GetDocumentsParams::GetDocumentsParams(
154 int64 start_changestamp, 142 int64 start_changestamp,
155 int64 root_feed_changestamp, 143 int64 root_feed_changestamp,
156 std::vector<DocumentFeed*>* feed_list, 144 std::vector<DocumentFeed*>* feed_list,
157 bool should_fetch_multiple_feeds,
satorux1 2012/08/17 11:01:31 so the parameter was unsed in the existing code?
kochi 2012/08/17 15:56:37 Yes, it is unused. The default value was true, and
158 const std::string& search_query, 145 const std::string& search_query,
159 const std::string& directory_resource_id, 146 const std::string& directory_resource_id,
160 const FileOperationCallback& callback, 147 const FileOperationCallback& callback,
161 GetDocumentsUiState* ui_state) 148 GetDocumentsUiState* ui_state)
162 : start_changestamp(start_changestamp), 149 : start_changestamp(start_changestamp),
163 root_feed_changestamp(root_feed_changestamp), 150 root_feed_changestamp(root_feed_changestamp),
164 feed_list(feed_list), 151 feed_list(feed_list),
165 should_fetch_multiple_feeds(should_fetch_multiple_feeds),
166 search_query(search_query), 152 search_query(search_query),
167 directory_resource_id(directory_resource_id), 153 directory_resource_id(directory_resource_id),
168 callback(callback), 154 callback(callback),
169 ui_state(ui_state) { 155 ui_state(ui_state) {
170 } 156 }
171 157
172 GetDocumentsParams::~GetDocumentsParams() { 158 GetDocumentsParams::~GetDocumentsParams() {
173 STLDeleteElements(feed_list.get()); 159 STLDeleteElements(feed_list.get());
174 } 160 }
175 161
162 LoadRootFeedParams::LoadRootFeedParams(
163 bool should_load_from_server,
164 const FileOperationCallback& callback)
165 : should_load_from_server(should_load_from_server),
166 load_error(GDATA_FILE_OK),
167 load_start_time(base::Time::Now()),
168 callback(callback) {
169 }
170
171 LoadRootFeedParams::~LoadRootFeedParams() {
172 }
173
174 // Defines set of parameters for calling GDataWapiFeedLoader::LoadFromServer().
175 // Value of |start_changestamp| determines the type of feed to load - 0 means
176 // root feed, every other value would trigger delta feed.
177 // In the case of loading the root feed we use |root_feed_changestamp| as its
178 // initial changestamp value since it does not come with that info.
179 //
180 // When all feeds are loaded, |feed_load_callback| is invoked with the retrieved
181 // feeds. Then |load_finished_callback| is invoked with the error code.
182 //
183 // If invoked as a part of content search, query will be set in |search_query|.
184 // If |feed_to_load| is set, this is feed url that will be used to load feed.
185 //
186 // |load_finished_callback| may be null.
187 // |feed_load_callback| must not be null.
188 struct GDataWapiFeedLoader::LoadFeedParams {
189 LoadFeedParams(ContentOrigin initial_origin,
190 const LoadDocumentFeedCallback& feed_load_callback)
191 : initial_origin(initial_origin),
192 start_changestamp(0),
193 root_feed_changestamp(0),
194 feed_load_callback(feed_load_callback) {}
195 ~LoadFeedParams() {}
196
197 ContentOrigin initial_origin;
198 int64 start_changestamp;
199 int64 root_feed_changestamp;
200 std::string search_query;
201 GURL feed_to_load;
202 std::string directory_resource_id;
203 FileOperationCallback load_finished_callback;
204 const LoadDocumentFeedCallback feed_load_callback;
205 };
206
176 // Defines set of parameters sent to callback OnNotifyDocumentFeedFetched(). 207 // Defines set of parameters sent to callback OnNotifyDocumentFeedFetched().
177 // This is a trick to update the number of fetched documents frequently on 208 // This is a trick to update the number of fetched documents frequently on
178 // UI. Due to performance reason, we need to fetch a number of files at 209 // UI. Due to performance reason, we need to fetch a number of files at
179 // a time. However, it'll take long time, and a user has no way to know 210 // a time. However, it'll take long time, and a user has no way to know
180 // the current update state. In order to make users confortable, 211 // the current update state. In order to make users confortable,
181 // we increment the number of fetched documents with more frequent but smaller 212 // we increment the number of fetched documents with more frequent but smaller
182 // steps than actual fetching. 213 // steps than actual fetching.
183 struct GetDocumentsUiState { 214 struct GetDocumentsUiState {
184 explicit GetDocumentsUiState(base::TimeTicks start_time) 215 explicit GetDocumentsUiState(base::TimeTicks start_time)
185 : num_fetched_documents(0), 216 : num_fetched_documents(0),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 297 }
267 298
268 void GDataWapiFeedLoader::OnGetAccountMetadata( 299 void GDataWapiFeedLoader::OnGetAccountMetadata(
269 ContentOrigin initial_origin, 300 ContentOrigin initial_origin,
270 int64 local_changestamp, 301 int64 local_changestamp,
271 const FileOperationCallback& callback, 302 const FileOperationCallback& callback,
272 GDataErrorCode status, 303 GDataErrorCode status,
273 scoped_ptr<base::Value> feed_data) { 304 scoped_ptr<base::Value> feed_data) {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 306
307 LoadFeedParams params(initial_origin,
308 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
309 weak_ptr_factory_.GetWeakPtr()));
310 params.start_changestamp = local_changestamp + 1;
311 params.load_finished_callback = callback;
312
276 GDataFileError error = util::GDataToGDataFileError(status); 313 GDataFileError error = util::GDataToGDataFileError(status);
277 if (error != GDATA_FILE_OK) { 314 if (error != GDATA_FILE_OK) {
278 // Get changes starting from the next changestamp from what we have locally. 315 // Get changes starting from the next changestamp from what we have locally.
279 LoadFromServer(initial_origin, 316 LoadFromServer(params);
280 local_changestamp + 1, 0,
281 true, /* should_fetch_multiple_feeds */
282 std::string() /* no search query */,
283 GURL(), /* feed not explicitly set */
284 std::string() /* no directory resource ID */,
285 callback,
286 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
287 weak_ptr_factory_.GetWeakPtr()));
288 return; 317 return;
289 } 318 }
290 319
291 scoped_ptr<AccountMetadataFeed> account_metadata; 320 scoped_ptr<AccountMetadataFeed> account_metadata;
292 if (feed_data.get()) { 321 if (feed_data.get()) {
293 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); 322 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data);
294 #ifndef NDEBUG 323 #ifndef NDEBUG
295 // Save account metadata feed for analysis. 324 // Save account metadata feed for analysis.
296 const FilePath path = 325 const FilePath path =
297 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( 326 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
298 kAccountMetadataFile); 327 kAccountMetadataFile);
299 util::PostBlockingPoolSequencedTask( 328 util::PostBlockingPoolSequencedTask(
300 FROM_HERE, 329 FROM_HERE,
301 blocking_task_runner_, 330 blocking_task_runner_,
302 base::Bind(&SaveFeedOnBlockingPoolForDebugging, 331 base::Bind(&SaveFeedOnBlockingPoolForDebugging,
303 path, base::Passed(&feed_data))); 332 path, base::Passed(&feed_data)));
304 #endif 333 #endif
305 } 334 }
306 335
307 if (!account_metadata.get()) { 336 if (!account_metadata.get()) {
308 LoadFromServer(initial_origin, 337 LoadFromServer(params);
309 local_changestamp + 1, 0,
310 true, /* should_fetch_multiple_feeds */
311 std::string() /* no search query */,
312 GURL(), /* feed not explicitly set */
313 std::string() /* no directory resource ID */,
314 callback,
315 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
316 weak_ptr_factory_.GetWeakPtr()));
satorux1 2012/08/17 11:01:31 glad that the large copy-paste is gone.
317 return; 338 return;
318 } 339 }
319 340
320 webapps_registry_->UpdateFromFeed(*account_metadata.get()); 341 webapps_registry_->UpdateFromFeed(*account_metadata.get());
321 342
322 bool changes_detected = true; 343 bool changes_detected = true;
323 if (local_changestamp >= account_metadata->largest_changestamp()) { 344 if (local_changestamp >= account_metadata->largest_changestamp()) {
324 if (local_changestamp > account_metadata->largest_changestamp()) { 345 if (local_changestamp > account_metadata->largest_changestamp()) {
325 LOG(WARNING) << "Cached client feed is fresher than server, client = " 346 LOG(WARNING) << "Cached client feed is fresher than server, client = "
326 << local_changestamp 347 << local_changestamp
327 << ", server = " 348 << ", server = "
328 << account_metadata->largest_changestamp(); 349 << account_metadata->largest_changestamp();
329 } 350 }
330 // If our cache holds the latest state from the server, change the 351 // If our cache holds the latest state from the server, change the
331 // state to FROM_SERVER. 352 // state to FROM_SERVER.
332 directory_service_->set_origin( 353 directory_service_->set_origin(
333 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); 354 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin);
334 changes_detected = false; 355 changes_detected = false;
335 } 356 }
336 357
337 // No changes detected, tell the client that the loading was successful. 358 // No changes detected, tell the client that the loading was successful.
338 if (!changes_detected) { 359 if (!changes_detected) {
339 if (!callback.is_null()) 360 if (!callback.is_null())
340 callback.Run(GDATA_FILE_OK); 361 callback.Run(GDATA_FILE_OK);
341 return; 362 return;
342 } 363 }
343 364
344 // Load changes from the server. 365 // Load changes from the server.
345 LoadFromServer(initial_origin, 366 params.start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0;
346 local_changestamp > 0 ? local_changestamp + 1 : 0, 367 params.root_feed_changestamp = account_metadata->largest_changestamp();
347 account_metadata->largest_changestamp(), 368 LoadFromServer(params);
348 true, /* should_fetch_multiple_feeds */
349 std::string() /* no search query */,
350 GURL(), /* feed not explicitly set */
351 std::string() /* no directory resource ID */,
352 callback,
353 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
354 weak_ptr_factory_.GetWeakPtr()));
355 } 369 }
356 370
357 void GDataWapiFeedLoader::OnGetAboutResource( 371 void GDataWapiFeedLoader::OnGetAboutResource(
358 ContentOrigin initial_origin, 372 ContentOrigin initial_origin,
359 int64 local_changestamp, 373 int64 local_changestamp,
360 const FileOperationCallback& callback, 374 const FileOperationCallback& callback,
361 GDataErrorCode status, 375 GDataErrorCode status,
362 scoped_ptr<base::Value> feed_data) { 376 scoped_ptr<base::Value> feed_data) {
363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
364 378
379 LoadFeedParams params(initial_origin,
380 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
381 weak_ptr_factory_.GetWeakPtr()));
382 params.load_finished_callback = callback;
383
365 GDataFileError error = util::GDataToGDataFileError(status); 384 GDataFileError error = util::GDataToGDataFileError(status);
366 if (error != GDATA_FILE_OK) { 385 if (error != GDATA_FILE_OK) {
367 // Get changes starting from the next changestamp from what we have locally. 386 // Get changes starting from the next changestamp from what we have locally.
368 LoadFromServer(initial_origin, 387 LoadFromServer(params);
369 local_changestamp + 1, 0,
370 true, /* should_fetch_multiple_feeds */
371 std::string() /* no search query */,
372 GURL(), /* feed not explicitly set */
373 std::string() /* no directory resource ID */,
374 callback,
375 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
376 weak_ptr_factory_.GetWeakPtr()));
377 return; 388 return;
378 } 389 }
379 390
380 scoped_ptr<AboutResource> about_resource; 391 scoped_ptr<AboutResource> about_resource;
381 if (feed_data.get()) 392 if (feed_data.get())
382 about_resource = AboutResource::CreateFrom(*feed_data); 393 about_resource = AboutResource::CreateFrom(*feed_data);
383 394
384 if (!about_resource.get()) { 395 if (!about_resource.get()) {
385 LoadFromServer(initial_origin, 396 LoadFromServer(params);
386 local_changestamp + 1, 0,
387 true, /* should_fetch_multiple_feeds */
388 std::string() /* no search query */,
389 GURL(), /* feed not explicitly set */
390 std::string() /* no directory resource ID */,
391 callback,
392 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
393 weak_ptr_factory_.GetWeakPtr()));
394 return; 397 return;
395 } 398 }
396 399
397 bool changes_detected = true; 400 bool changes_detected = true;
398 int64 largest_changestamp = about_resource->largest_change_id(); 401 int64 largest_changestamp = about_resource->largest_change_id();
399 directory_service_->InitializeRootEntry(about_resource->root_folder_id()); 402 directory_service_->InitializeRootEntry(about_resource->root_folder_id());
400 403
401 if (local_changestamp >= largest_changestamp) { 404 if (local_changestamp >= largest_changestamp) {
402 if (local_changestamp > largest_changestamp) { 405 if (local_changestamp > largest_changestamp) {
403 LOG(WARNING) << "Cached client feed is fresher than server, client = " 406 LOG(WARNING) << "Cached client feed is fresher than server, client = "
404 << local_changestamp 407 << local_changestamp
405 << ", server = " 408 << ", server = "
406 << largest_changestamp; 409 << largest_changestamp;
407 } 410 }
408 // If our cache holds the latest state from the server, change the 411 // If our cache holds the latest state from the server, change the
409 // state to FROM_SERVER. 412 // state to FROM_SERVER.
410 directory_service_->set_origin( 413 directory_service_->set_origin(
411 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); 414 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin);
412 changes_detected = false; 415 changes_detected = false;
413 } 416 }
414 417
415 // No changes detected, tell the client that the loading was successful. 418 // No changes detected, tell the client that the loading was successful.
416 if (!changes_detected) { 419 if (!changes_detected) {
417 if (!callback.is_null()) 420 if (!callback.is_null())
418 callback.Run(GDATA_FILE_OK); 421 callback.Run(GDATA_FILE_OK);
419 return; 422 return;
420 } 423 }
421 424
422 // Load changes from the server. 425 // Load changes from the server.
423 LoadFromServer(initial_origin, 426 params.start_changestamp = local_changestamp > 0 ? local_changestamp + 1 : 0;
424 local_changestamp > 0 ? local_changestamp + 1 : 0, 427 params.root_feed_changestamp = largest_changestamp;
425 largest_changestamp, 428 LoadFromServer(params);
426 true, /* should_fetch_multiple_feeds */
427 std::string() /* no search query */,
428 GURL(), /* feed not explicitly set */
429 std::string() /* no directory resource ID */,
430 callback,
431 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded,
432 weak_ptr_factory_.GetWeakPtr()));
433 } 429 }
434 430
435 void GDataWapiFeedLoader::OnGetApplicationList( 431 void GDataWapiFeedLoader::OnGetApplicationList(
436 GDataErrorCode status, 432 GDataErrorCode status,
437 scoped_ptr<base::Value> json) { 433 scoped_ptr<base::Value> json) {
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
439 435
440 GDataFileError error = util::GDataToGDataFileError(status); 436 GDataFileError error = util::GDataToGDataFileError(status);
441 if (error != GDATA_FILE_OK) 437 if (error != GDATA_FILE_OK)
442 return; 438 return;
443 439
444 if (json.get()) { 440 if (json.get()) {
445 scoped_ptr<AppList> applist(AppList::CreateFrom(*json)); 441 scoped_ptr<AppList> applist(AppList::CreateFrom(*json));
446 if (applist.get()) { 442 if (applist.get()) {
447 VLOG(1) << "applist get success"; 443 VLOG(1) << "applist get success";
448 webapps_registry_->UpdateFromApplicationList(*applist.get()); 444 webapps_registry_->UpdateFromApplicationList(*applist.get());
449 } 445 }
450 } 446 }
451 } 447 }
452 448
453 // TODO(kochi): Fix too many parameters. http://crbug.com/141359 449 void GDataWapiFeedLoader::LoadFromServer(const LoadFeedParams& params) {
454 void GDataWapiFeedLoader::LoadFromServer(
455 ContentOrigin initial_origin,
456 int64 start_changestamp,
457 int64 root_feed_changestamp,
458 bool should_fetch_multiple_feeds,
459 const std::string& search_query,
460 const GURL& feed_to_load,
461 const std::string& directory_resource_id,
462 const FileOperationCallback& load_finished_callback,
463 const LoadDocumentFeedCallback& feed_load_callback) {
464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
465 DCHECK(!feed_load_callback.is_null());
466 451
467 // |feed_list| will contain the list of all collected feed updates that 452 // |feed_list| will contain the list of all collected feed updates that
468 // we will receive through calls of DocumentsService::GetDocuments(). 453 // we will receive through calls of DocumentsService::GetDocuments().
469 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 454 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
470 new std::vector<DocumentFeed*>); 455 new std::vector<DocumentFeed*>);
471 const base::TimeTicks start_time = base::TimeTicks::Now(); 456 const base::TimeTicks start_time = base::TimeTicks::Now();
472 457
473 if (gdata::util::IsDriveV2ApiEnabled()) { 458 if (gdata::util::IsDriveV2ApiEnabled()) {
474 documents_service_->GetChangelist( 459 documents_service_->GetChangelist(
475 feed_to_load, 460 params.feed_to_load,
476 start_changestamp, 461 params.start_changestamp,
477 base::Bind(&GDataWapiFeedLoader::OnGetChangelist, 462 base::Bind(&GDataWapiFeedLoader::OnGetChangelist,
478 weak_ptr_factory_.GetWeakPtr(), 463 weak_ptr_factory_.GetWeakPtr(),
479 initial_origin, 464 params.initial_origin,
480 feed_load_callback, 465 params.feed_load_callback,
481 base::Owned(new GetDocumentsParams( 466 base::Owned(new GetDocumentsParams(
482 start_changestamp, 467 params.start_changestamp,
483 root_feed_changestamp, 468 params.root_feed_changestamp,
484 feed_list.release(), 469 feed_list.release(),
485 should_fetch_multiple_feeds, 470 params.search_query,
486 search_query, 471 params.directory_resource_id,
487 directory_resource_id, 472 params.load_finished_callback,
488 load_finished_callback,
489 NULL)), 473 NULL)),
490 start_time)); 474 start_time));
491 return; 475 return;
492 } 476 }
493 477
494 documents_service_->GetDocuments( 478 documents_service_->GetDocuments(
495 feed_to_load, 479 params.feed_to_load,
496 start_changestamp, 480 params.start_changestamp,
497 search_query, 481 params.search_query,
498 directory_resource_id, 482 params.directory_resource_id,
499 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, 483 base::Bind(&GDataWapiFeedLoader::OnGetDocuments,
500 weak_ptr_factory_.GetWeakPtr(), 484 weak_ptr_factory_.GetWeakPtr(),
501 initial_origin, 485 params.initial_origin,
502 feed_load_callback, 486 params.feed_load_callback,
503 base::Owned(new GetDocumentsParams(start_changestamp, 487 base::Owned(
504 root_feed_changestamp, 488 new GetDocumentsParams(params.start_changestamp,
505 feed_list.release(), 489 params.root_feed_changestamp,
506 should_fetch_multiple_feeds, 490 feed_list.release(),
507 search_query, 491 params.search_query,
508 directory_resource_id, 492 params.directory_resource_id,
509 load_finished_callback, 493 params.load_finished_callback,
510 NULL)), 494 NULL)),
511 start_time)); 495 start_time));
512 } 496 }
513 497
498 void GDataWapiFeedLoader::LoadDirectoryFromServer(
499 ContentOrigin initial_origin,
500 const std::string& directory_resource_id,
501 const LoadDocumentFeedCallback& feed_load_callback) {
502 LoadFeedParams params(initial_origin, feed_load_callback);
503 params.directory_resource_id = directory_resource_id;
504 LoadFromServer(params);
505 }
506
507 void GDataWapiFeedLoader::SearchFromServer(
508 ContentOrigin initial_origin,
509 const std::string& search_query,
510 const GURL& next_feed,
511 const LoadDocumentFeedCallback& feed_load_callback) {
512 LoadFeedParams params(initial_origin, feed_load_callback);
513 params.search_query = search_query;
514 params.feed_to_load = next_feed;
515 LoadFromServer(params);
516 }
517
514 void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params, 518 void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params,
515 GDataFileError error) { 519 GDataFileError error) {
516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
517 521
518 if (error != GDATA_FILE_OK) { 522 if (error != GDATA_FILE_OK) {
519 if (!params->callback.is_null()) 523 if (!params->callback.is_null())
520 params->callback.Run(error); 524 params->callback.Run(error);
521 return; 525 return;
522 } 526 }
523 527
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 598
595 // Add the current feed to the list of collected feeds for this directory. 599 // Add the current feed to the list of collected feeds for this directory.
596 params->feed_list->push_back(current_feed.release()); 600 params->feed_list->push_back(current_feed.release());
597 601
598 // Compute and notify the number of entries fetched so far. 602 // Compute and notify the number of entries fetched so far.
599 int num_accumulated_entries = 0; 603 int num_accumulated_entries = 0;
600 for (size_t i = 0; i < params->feed_list->size(); ++i) 604 for (size_t i = 0; i < params->feed_list->size(); ++i)
601 num_accumulated_entries += params->feed_list->at(i)->entries().size(); 605 num_accumulated_entries += params->feed_list->at(i)->entries().size();
602 606
603 // Check if we need to collect more data to complete the directory list. 607 // Check if we need to collect more data to complete the directory list.
604 if (params->should_fetch_multiple_feeds && has_next_feed_url && 608 if (has_next_feed_url && !next_feed_url.is_empty()) {
605 !next_feed_url.is_empty()) {
606 // Post an UI update event to make the UI smoother. 609 // Post an UI update event to make the UI smoother.
607 GetDocumentsUiState* ui_state = params->ui_state.get(); 610 GetDocumentsUiState* ui_state = params->ui_state.get();
608 if (ui_state == NULL) { 611 if (ui_state == NULL) {
609 ui_state = new GetDocumentsUiState(base::TimeTicks::Now()); 612 ui_state = new GetDocumentsUiState(base::TimeTicks::Now());
610 params->ui_state.reset(ui_state); 613 params->ui_state.reset(ui_state);
611 } 614 }
612 DCHECK(ui_state); 615 DCHECK(ui_state);
613 616
614 if ((ui_state->num_fetched_documents - ui_state->num_showing_documents) 617 if ((ui_state->num_fetched_documents - ui_state->num_showing_documents)
615 < kFetchUiUpdateStep) { 618 < kFetchUiUpdateStep) {
(...skipping 15 matching lines...) Expand all
631 params->directory_resource_id, 634 params->directory_resource_id,
632 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, 635 base::Bind(&GDataWapiFeedLoader::OnGetDocuments,
633 weak_ptr_factory_.GetWeakPtr(), 636 weak_ptr_factory_.GetWeakPtr(),
634 initial_origin, 637 initial_origin,
635 callback, 638 callback,
636 base::Owned( 639 base::Owned(
637 new GetDocumentsParams( 640 new GetDocumentsParams(
638 params->start_changestamp, 641 params->start_changestamp,
639 params->root_feed_changestamp, 642 params->root_feed_changestamp,
640 params->feed_list.release(), 643 params->feed_list.release(),
641 params->should_fetch_multiple_feeds,
642 params->search_query, 644 params->search_query,
643 params->directory_resource_id, 645 params->directory_resource_id,
644 params->callback, 646 params->callback,
645 params->ui_state.release())), 647 params->ui_state.release())),
646 start_time)); 648 start_time));
647 return; 649 return;
648 } 650 }
649 651
650 // Notify the observers that all document feeds are fetched. 652 // Notify the observers that all document feeds are fetched.
651 FOR_EACH_OBSERVER(Observer, observers_, 653 FOR_EACH_OBSERVER(Observer, observers_,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 scoped_ptr<DocumentFeed> feed = 713 scoped_ptr<DocumentFeed> feed =
712 DocumentFeed::CreateFromChangeList(*current_feed); 714 DocumentFeed::CreateFromChangeList(*current_feed);
713 params->feed_list->push_back(feed.release()); 715 params->feed_list->push_back(feed.release());
714 716
715 // Compute and notify the number of entries fetched so far. 717 // Compute and notify the number of entries fetched so far.
716 int num_accumulated_entries = 0; 718 int num_accumulated_entries = 0;
717 for (size_t i = 0; i < params->feed_list->size(); ++i) 719 for (size_t i = 0; i < params->feed_list->size(); ++i)
718 num_accumulated_entries += params->feed_list->at(i)->entries().size(); 720 num_accumulated_entries += params->feed_list->at(i)->entries().size();
719 721
720 // Check if we need to collect more data to complete the directory list. 722 // Check if we need to collect more data to complete the directory list.
721 if (params->should_fetch_multiple_feeds && has_next_feed) { 723 if (has_next_feed) {
722 724
723 // Post an UI update event to make the UI smoother. 725 // Post an UI update event to make the UI smoother.
724 GetDocumentsUiState* ui_state = params->ui_state.get(); 726 GetDocumentsUiState* ui_state = params->ui_state.get();
725 if (ui_state == NULL) { 727 if (ui_state == NULL) {
726 ui_state = new GetDocumentsUiState(base::TimeTicks::Now()); 728 ui_state = new GetDocumentsUiState(base::TimeTicks::Now());
727 params->ui_state.reset(ui_state); 729 params->ui_state.reset(ui_state);
728 } 730 }
729 DCHECK(ui_state); 731 DCHECK(ui_state);
730 732
731 if ((ui_state->num_fetched_documents - ui_state->num_showing_documents) 733 if ((ui_state->num_fetched_documents - ui_state->num_showing_documents)
(...skipping 14 matching lines...) Expand all
746 params->start_changestamp, 748 params->start_changestamp,
747 base::Bind(&GDataWapiFeedLoader::OnGetChangelist, 749 base::Bind(&GDataWapiFeedLoader::OnGetChangelist,
748 weak_ptr_factory_.GetWeakPtr(), 750 weak_ptr_factory_.GetWeakPtr(),
749 initial_origin, 751 initial_origin,
750 callback, 752 callback,
751 base::Owned( 753 base::Owned(
752 new GetDocumentsParams( 754 new GetDocumentsParams(
753 params->start_changestamp, 755 params->start_changestamp,
754 params->root_feed_changestamp, 756 params->root_feed_changestamp,
755 params->feed_list.release(), 757 params->feed_list.release(),
756 params->should_fetch_multiple_feeds,
757 params->search_query, 758 params->search_query,
758 params->directory_resource_id, 759 params->directory_resource_id,
759 params->callback, 760 params->callback,
760 NULL)), 761 NULL)),
761 start_time)); 762 start_time));
762 return; 763 return;
763 } 764 }
764 765
765 // Notify the observers that all document feeds are fetched. 766 // Notify the observers that all document feeds are fetched.
766 FOR_EACH_OBSERVER(Observer, observers_, 767 FOR_EACH_OBSERVER(Observer, observers_,
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 dir_iter != changed_dirs.end(); ++dir_iter) { 953 dir_iter != changed_dirs.end(); ++dir_iter) {
953 FOR_EACH_OBSERVER(Observer, observers_, 954 FOR_EACH_OBSERVER(Observer, observers_,
954 OnDirectoryChanged(*dir_iter)); 955 OnDirectoryChanged(*dir_iter));
955 } 956 }
956 } 957 }
957 958
958 return error; 959 return error;
959 } 960 }
960 961
961 } // namespace gdata 962 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698