Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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( | 141 LoadRootFeedParams::LoadRootFeedParams( |
| 142 FilePath search_file_path, | 142 FilePath search_file_path, |
| 143 bool should_load_from_server, | 143 bool should_load_from_server, |
| 144 const FindEntryCallback& callback) | 144 const FileOperationCallback& callback) |
| 145 : search_file_path(search_file_path), | 145 : search_file_path(search_file_path), |
| 146 should_load_from_server(should_load_from_server), | 146 should_load_from_server(should_load_from_server), |
| 147 load_error(GDATA_FILE_OK), | 147 load_error(GDATA_FILE_OK), |
| 148 load_start_time(base::Time::Now()), | 148 load_start_time(base::Time::Now()), |
| 149 callback(callback) { | 149 callback(callback) { |
| 150 } | 150 } |
| 151 | 151 |
| 152 LoadRootFeedParams::~LoadRootFeedParams() { | 152 LoadRootFeedParams::~LoadRootFeedParams() { |
| 153 } | 153 } |
| 154 | 154 |
| 155 GetDocumentsParams::GetDocumentsParams( | 155 GetDocumentsParams::GetDocumentsParams( |
| 156 int64 start_changestamp, | 156 int64 start_changestamp, |
| 157 int64 root_feed_changestamp, | 157 int64 root_feed_changestamp, |
| 158 std::vector<DocumentFeed*>* feed_list, | 158 std::vector<DocumentFeed*>* feed_list, |
| 159 bool should_fetch_multiple_feeds, | 159 bool should_fetch_multiple_feeds, |
| 160 const FilePath& search_file_path, | 160 const FilePath& search_file_path, |
| 161 const std::string& search_query, | 161 const std::string& search_query, |
| 162 const std::string& directory_resource_id, | 162 const std::string& directory_resource_id, |
| 163 const FindEntryCallback& callback, | 163 const FileOperationCallback& callback, |
| 164 GetDocumentsUiState* ui_state) | 164 GetDocumentsUiState* ui_state) |
| 165 : start_changestamp(start_changestamp), | 165 : start_changestamp(start_changestamp), |
| 166 root_feed_changestamp(root_feed_changestamp), | 166 root_feed_changestamp(root_feed_changestamp), |
| 167 feed_list(feed_list), | 167 feed_list(feed_list), |
| 168 should_fetch_multiple_feeds(should_fetch_multiple_feeds), | 168 should_fetch_multiple_feeds(should_fetch_multiple_feeds), |
| 169 search_file_path(search_file_path), | 169 search_file_path(search_file_path), |
| 170 search_query(search_query), | 170 search_query(search_query), |
| 171 directory_resource_id(directory_resource_id), | 171 directory_resource_id(directory_resource_id), |
| 172 callback(callback), | 172 callback(callback), |
| 173 ui_state(ui_state) { | 173 ui_state(ui_state) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 | 231 |
| 232 void GDataWapiFeedLoader::RemoveObserver(Observer* observer) { | 232 void GDataWapiFeedLoader::RemoveObserver(Observer* observer) { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 observers_.RemoveObserver(observer); | 234 observers_.RemoveObserver(observer); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void GDataWapiFeedLoader::ReloadFromServerIfNeeded( | 237 void GDataWapiFeedLoader::ReloadFromServerIfNeeded( |
| 238 ContentOrigin initial_origin, | 238 ContentOrigin initial_origin, |
| 239 int64 local_changestamp, | 239 int64 local_changestamp, |
| 240 const FilePath& search_file_path, | 240 const FilePath& search_file_path, |
| 241 const FindEntryCallback& callback) { | 241 const FileOperationCallback& callback) { |
| 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 243 | 243 |
| 244 DVLOG(1) << "ReloadFeedFromServerIfNeeded local_changestamp=" | 244 DVLOG(1) << "ReloadFeedFromServerIfNeeded local_changestamp=" |
| 245 << local_changestamp << ", initial_origin=" << initial_origin; | 245 << local_changestamp << ", initial_origin=" << initial_origin; |
| 246 | 246 |
| 247 // First fetch the latest changestamp to see if there were any new changes | 247 // First fetch the latest changestamp to see if there were any new changes |
| 248 // there at all. | 248 // there at all. |
| 249 if (gdata::util::IsDriveV2ApiEnabled()) { | 249 if (gdata::util::IsDriveV2ApiEnabled()) { |
| 250 documents_service_->GetAboutResource( | 250 documents_service_->GetAboutResource( |
| 251 base::Bind(&GDataWapiFeedLoader::OnGetAboutResource, | 251 base::Bind(&GDataWapiFeedLoader::OnGetAboutResource, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 263 initial_origin, | 263 initial_origin, |
| 264 local_changestamp, | 264 local_changestamp, |
| 265 search_file_path, | 265 search_file_path, |
| 266 callback)); | 266 callback)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void GDataWapiFeedLoader::OnGetAccountMetadata( | 269 void GDataWapiFeedLoader::OnGetAccountMetadata( |
| 270 ContentOrigin initial_origin, | 270 ContentOrigin initial_origin, |
| 271 int64 local_changestamp, | 271 int64 local_changestamp, |
| 272 const FilePath& search_file_path, | 272 const FilePath& search_file_path, |
| 273 const FindEntryCallback& callback, | 273 const FileOperationCallback& callback, |
| 274 GDataErrorCode status, | 274 GDataErrorCode status, |
| 275 scoped_ptr<base::Value> feed_data) { | 275 scoped_ptr<base::Value> feed_data) { |
| 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 277 | 277 |
| 278 GDataFileError error = util::GDataToGDataFileError(status); | 278 GDataFileError error = util::GDataToGDataFileError(status); |
| 279 if (error != GDATA_FILE_OK) { | 279 if (error != GDATA_FILE_OK) { |
| 280 // Get changes starting from the next changestamp from what we have locally. | 280 // Get changes starting from the next changestamp from what we have locally. |
| 281 LoadFromServer(initial_origin, | 281 LoadFromServer(initial_origin, |
| 282 local_changestamp + 1, 0, | 282 local_changestamp + 1, 0, |
| 283 true, /* should_fetch_multiple_feeds */ | 283 true, /* should_fetch_multiple_feeds */ |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 << ", server = " | 331 << ", server = " |
| 332 << account_metadata->largest_changestamp(); | 332 << account_metadata->largest_changestamp(); |
| 333 } | 333 } |
| 334 // If our cache holds the latest state from the server, change the | 334 // If our cache holds the latest state from the server, change the |
| 335 // state to FROM_SERVER. | 335 // state to FROM_SERVER. |
| 336 directory_service_->set_origin( | 336 directory_service_->set_origin( |
| 337 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); | 337 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); |
| 338 changes_detected = false; | 338 changes_detected = false; |
| 339 } | 339 } |
| 340 | 340 |
| 341 // No changes detected, continue with search as planned. | 341 // No changes detected, tell the client that the loading was successful. |
| 342 if (!changes_detected) { | 342 if (!changes_detected) { |
| 343 if (!callback.is_null()) { | 343 if (!callback.is_null()) |
| 344 directory_service_->FindEntryByPathAndRunSync(search_file_path, | 344 callback.Run(GDATA_FILE_OK); |
| 345 callback); | |
| 346 } | |
| 347 return; | 345 return; |
| 348 } | 346 } |
| 349 | 347 |
| 350 // Load changes from the server. | 348 // Load changes from the server. |
| 351 LoadFromServer(initial_origin, | 349 LoadFromServer(initial_origin, |
| 352 local_changestamp > 0 ? local_changestamp + 1 : 0, | 350 local_changestamp > 0 ? local_changestamp + 1 : 0, |
| 353 account_metadata->largest_changestamp(), | 351 account_metadata->largest_changestamp(), |
| 354 true, /* should_fetch_multiple_feeds */ | 352 true, /* should_fetch_multiple_feeds */ |
| 355 search_file_path, | 353 search_file_path, |
| 356 std::string() /* no search query */, | 354 std::string() /* no search query */, |
| 357 GURL(), /* feed not explicitly set */ | 355 GURL(), /* feed not explicitly set */ |
| 358 std::string() /* no directory resource ID */, | 356 std::string() /* no directory resource ID */, |
| 359 callback, | 357 callback, |
| 360 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, | 358 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
| 361 weak_ptr_factory_.GetWeakPtr())); | 359 weak_ptr_factory_.GetWeakPtr())); |
| 362 } | 360 } |
| 363 | 361 |
| 364 void GDataWapiFeedLoader::OnGetAboutResource( | 362 void GDataWapiFeedLoader::OnGetAboutResource( |
| 365 ContentOrigin initial_origin, | 363 ContentOrigin initial_origin, |
| 366 int64 local_changestamp, | 364 int64 local_changestamp, |
| 367 const FilePath& search_file_path, | 365 const FilePath& search_file_path, |
| 368 const FindEntryCallback& callback, | 366 const FileOperationCallback& callback, |
| 369 GDataErrorCode status, | 367 GDataErrorCode status, |
| 370 scoped_ptr<base::Value> feed_data) { | 368 scoped_ptr<base::Value> feed_data) { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 372 | 370 |
| 373 GDataFileError error = util::GDataToGDataFileError(status); | 371 GDataFileError error = util::GDataToGDataFileError(status); |
| 374 if (error != GDATA_FILE_OK) { | 372 if (error != GDATA_FILE_OK) { |
| 375 // Get changes starting from the next changestamp from what we have locally. | 373 // Get changes starting from the next changestamp from what we have locally. |
| 376 LoadFromServer(initial_origin, | 374 LoadFromServer(initial_origin, |
| 377 local_changestamp + 1, 0, | 375 local_changestamp + 1, 0, |
| 378 true, /* should_fetch_multiple_feeds */ | 376 true, /* should_fetch_multiple_feeds */ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 << ", server = " | 413 << ", server = " |
| 416 << largest_changestamp; | 414 << largest_changestamp; |
| 417 } | 415 } |
| 418 // If our cache holds the latest state from the server, change the | 416 // If our cache holds the latest state from the server, change the |
| 419 // state to FROM_SERVER. | 417 // state to FROM_SERVER. |
| 420 directory_service_->set_origin( | 418 directory_service_->set_origin( |
| 421 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); | 419 initial_origin == FROM_CACHE ? FROM_SERVER : initial_origin); |
| 422 changes_detected = false; | 420 changes_detected = false; |
| 423 } | 421 } |
| 424 | 422 |
| 425 // No changes detected, continue with search as planned. | 423 // No changes detected, tell the client that the loading was successful. |
| 426 if (!changes_detected) { | 424 if (!changes_detected) { |
| 427 if (!callback.is_null()) { | 425 if (!callback.is_null()) |
| 428 directory_service_->FindEntryByPathAndRunSync(search_file_path, | 426 callback.Run(GDATA_FILE_OK); |
| 429 callback); | |
| 430 } | |
| 431 return; | 427 return; |
| 432 } | 428 } |
| 433 | 429 |
| 434 // Load changes from the server. | 430 // Load changes from the server. |
| 435 LoadFromServer(initial_origin, | 431 LoadFromServer(initial_origin, |
| 436 local_changestamp > 0 ? local_changestamp + 1 : 0, | 432 local_changestamp > 0 ? local_changestamp + 1 : 0, |
| 437 largest_changestamp, | 433 largest_changestamp, |
| 438 true, /* should_fetch_multiple_feeds */ | 434 true, /* should_fetch_multiple_feeds */ |
| 439 search_file_path, | 435 search_file_path, |
| 440 std::string() /* no search query */, | 436 std::string() /* no search query */, |
| 441 GURL(), /* feed not explicitly set */ | 437 GURL(), /* feed not explicitly set */ |
| 442 std::string() /* no directory resource ID */, | 438 std::string() /* no directory resource ID */, |
| 443 callback, | 439 callback, |
| 444 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, | 440 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
| 445 weak_ptr_factory_.GetWeakPtr())); | 441 weak_ptr_factory_.GetWeakPtr())); |
| 446 } | 442 } |
| 447 | 443 |
| 448 // TODO(kochi): Fix too many parameters. http://crbug.com/141359 | 444 // TODO(kochi): Fix too many parameters. http://crbug.com/141359 |
| 449 void GDataWapiFeedLoader::LoadFromServer( | 445 void GDataWapiFeedLoader::LoadFromServer( |
| 450 ContentOrigin initial_origin, | 446 ContentOrigin initial_origin, |
| 451 int64 start_changestamp, | 447 int64 start_changestamp, |
| 452 int64 root_feed_changestamp, | 448 int64 root_feed_changestamp, |
| 453 bool should_fetch_multiple_feeds, | 449 bool should_fetch_multiple_feeds, |
| 454 const FilePath& search_file_path, | 450 const FilePath& search_file_path, |
| 455 const std::string& search_query, | 451 const std::string& search_query, |
| 456 const GURL& feed_to_load, | 452 const GURL& feed_to_load, |
| 457 const std::string& directory_resource_id, | 453 const std::string& directory_resource_id, |
| 458 const FindEntryCallback& entry_found_callback, | 454 const FileOperationCallback& load_finished_callback, |
| 459 const LoadDocumentFeedCallback& feed_load_callback) { | 455 const LoadDocumentFeedCallback& feed_load_callback) { |
| 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 457 DCHECK(!feed_load_callback.is_null()); | |
| 461 | 458 |
| 462 // |feed_list| will contain the list of all collected feed updates that | 459 // |feed_list| will contain the list of all collected feed updates that |
| 463 // we will receive through calls of DocumentsService::GetDocuments(). | 460 // we will receive through calls of DocumentsService::GetDocuments(). |
| 464 scoped_ptr<std::vector<DocumentFeed*> > feed_list( | 461 scoped_ptr<std::vector<DocumentFeed*> > feed_list( |
| 465 new std::vector<DocumentFeed*>); | 462 new std::vector<DocumentFeed*>); |
| 466 const base::TimeTicks start_time = base::TimeTicks::Now(); | 463 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 467 | 464 |
| 468 if (gdata::util::IsDriveV2ApiEnabled()) { | 465 if (gdata::util::IsDriveV2ApiEnabled()) { |
| 469 documents_service_->GetChangelist( | 466 documents_service_->GetChangelist( |
| 470 feed_to_load, | 467 feed_to_load, |
| 471 start_changestamp, | 468 start_changestamp, |
| 472 base::Bind(&GDataWapiFeedLoader::OnGetChangelist, | 469 base::Bind(&GDataWapiFeedLoader::OnGetChangelist, |
| 473 weak_ptr_factory_.GetWeakPtr(), | 470 weak_ptr_factory_.GetWeakPtr(), |
| 474 initial_origin, | 471 initial_origin, |
| 475 feed_load_callback, | 472 feed_load_callback, |
| 476 base::Owned(new GetDocumentsParams( | 473 base::Owned(new GetDocumentsParams( |
| 477 start_changestamp, | 474 start_changestamp, |
| 478 root_feed_changestamp, | 475 root_feed_changestamp, |
| 479 feed_list.release(), | 476 feed_list.release(), |
| 480 should_fetch_multiple_feeds, | 477 should_fetch_multiple_feeds, |
| 481 search_file_path, | 478 search_file_path, |
| 482 search_query, | 479 search_query, |
| 483 directory_resource_id, | 480 directory_resource_id, |
| 484 entry_found_callback, | 481 load_finished_callback, |
| 485 NULL)), | 482 NULL)), |
| 486 start_time)); | 483 start_time)); |
| 487 return; | 484 return; |
| 488 } | 485 } |
| 489 | 486 |
| 490 documents_service_->GetDocuments( | 487 documents_service_->GetDocuments( |
| 491 feed_to_load, | 488 feed_to_load, |
| 492 start_changestamp, | 489 start_changestamp, |
| 493 search_query, | 490 search_query, |
| 494 directory_resource_id, | 491 directory_resource_id, |
| 495 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, | 492 base::Bind(&GDataWapiFeedLoader::OnGetDocuments, |
| 496 weak_ptr_factory_.GetWeakPtr(), | 493 weak_ptr_factory_.GetWeakPtr(), |
| 497 initial_origin, | 494 initial_origin, |
| 498 feed_load_callback, | 495 feed_load_callback, |
| 499 base::Owned(new GetDocumentsParams(start_changestamp, | 496 base::Owned(new GetDocumentsParams(start_changestamp, |
| 500 root_feed_changestamp, | 497 root_feed_changestamp, |
| 501 feed_list.release(), | 498 feed_list.release(), |
| 502 should_fetch_multiple_feeds, | 499 should_fetch_multiple_feeds, |
| 503 search_file_path, | 500 search_file_path, |
| 504 search_query, | 501 search_query, |
| 505 directory_resource_id, | 502 directory_resource_id, |
| 506 entry_found_callback, | 503 load_finished_callback, |
| 507 NULL)), | 504 NULL)), |
| 508 start_time)); | 505 start_time)); |
| 509 } | 506 } |
| 510 | 507 |
| 511 void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params, | 508 void GDataWapiFeedLoader::OnFeedFromServerLoaded(GetDocumentsParams* params, |
| 512 GDataFileError error) { | 509 GDataFileError error) { |
| 513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 514 | 511 |
| 515 if (error != GDATA_FILE_OK) { | 512 if (error != GDATA_FILE_OK) { |
| 516 if (!params->callback.is_null()) | 513 if (!params->callback.is_null()) |
| 517 params->callback.Run(error, NULL); | 514 params->callback.Run(error); |
| 518 return; | 515 return; |
| 519 } | 516 } |
| 520 | 517 |
| 521 error = UpdateFromFeed(*params->feed_list, | 518 error = UpdateFromFeed(*params->feed_list, |
| 522 params->start_changestamp, | 519 params->start_changestamp, |
| 523 params->root_feed_changestamp); | 520 params->root_feed_changestamp); |
| 524 | 521 |
| 525 if (error != GDATA_FILE_OK) { | 522 if (error != GDATA_FILE_OK) { |
| 526 if (!params->callback.is_null()) | 523 if (!params->callback.is_null()) |
| 527 params->callback.Run(error, NULL); | 524 params->callback.Run(error); |
| 528 | 525 |
| 529 return; | 526 return; |
| 530 } | 527 } |
| 531 | 528 |
| 532 // Save file system metadata to disk. | 529 // Save file system metadata to disk. |
| 533 SaveFileSystem(); | 530 SaveFileSystem(); |
| 534 | 531 |
| 535 // If we had someone to report this too, then this retrieval was done in a | 532 // Tell the client that the loading was successful. |
| 536 // context of search... so continue search. | |
| 537 if (!params->callback.is_null()) { | 533 if (!params->callback.is_null()) { |
| 538 directory_service_->FindEntryByPathAndRunSync(params->search_file_path, | 534 params->callback.Run(GDATA_FILE_OK); |
| 539 params->callback); | |
| 540 } | 535 } |
| 541 | 536 |
| 542 FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); | 537 FOR_EACH_OBSERVER(Observer, observers_, OnFeedFromServerLoaded()); |
| 543 } | 538 } |
| 544 | 539 |
| 545 void GDataWapiFeedLoader::OnGetDocuments( | 540 void GDataWapiFeedLoader::OnGetDocuments( |
| 546 ContentOrigin initial_origin, | 541 ContentOrigin initial_origin, |
| 547 const LoadDocumentFeedCallback& callback, | 542 const LoadDocumentFeedCallback& callback, |
| 548 GetDocumentsParams* params, | 543 GetDocumentsParams* params, |
| 549 base::TimeTicks start_time, | 544 base::TimeTicks start_time, |
| 550 GDataErrorCode status, | 545 GDataErrorCode status, |
| 551 scoped_ptr<base::Value> data) { | 546 scoped_ptr<base::Value> data) { |
| 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 548 DCHECK(!callback.is_null()); | |
| 553 | 549 |
| 554 if (params->feed_list->empty()) { | 550 if (params->feed_list->empty()) { |
| 555 UMA_HISTOGRAM_TIMES("Gdata.InitialFeedLoadTime", | 551 UMA_HISTOGRAM_TIMES("Gdata.InitialFeedLoadTime", |
| 556 base::TimeTicks::Now() - start_time); | 552 base::TimeTicks::Now() - start_time); |
| 557 } | 553 } |
| 558 | 554 |
| 559 GDataFileError error = util::GDataToGDataFileError(status); | 555 GDataFileError error = util::GDataToGDataFileError(status); |
| 560 if (error == GDATA_FILE_OK && | 556 if (error == GDATA_FILE_OK && |
| 561 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) { | 557 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) { |
| 562 error = GDATA_FILE_ERROR_FAILED; | 558 error = GDATA_FILE_ERROR_FAILED; |
| 563 } | 559 } |
| 564 | 560 |
| 565 if (error != GDATA_FILE_OK) { | 561 if (error != GDATA_FILE_OK) { |
| 566 directory_service_->set_origin(initial_origin); | 562 directory_service_->set_origin(initial_origin); |
| 567 | 563 callback.Run(params, error); |
| 568 if (!callback.is_null()) | |
| 569 callback.Run(params, error); | |
| 570 | |
| 571 return; | 564 return; |
| 572 } | 565 } |
| 573 | 566 |
| 574 GURL next_feed_url; | 567 GURL next_feed_url; |
| 575 scoped_ptr<DocumentFeed> current_feed(DocumentFeed::ExtractAndParse(*data)); | 568 scoped_ptr<DocumentFeed> current_feed(DocumentFeed::ExtractAndParse(*data)); |
| 576 if (!current_feed.get()) { | 569 if (!current_feed.get()) { |
| 577 if (!callback.is_null()) { | 570 callback.Run(params, GDATA_FILE_ERROR_FAILED); |
| 578 callback.Run(params, GDATA_FILE_ERROR_FAILED); | |
| 579 } | |
| 580 return; | 571 return; |
| 581 } | 572 } |
| 582 const bool has_next_feed_url = current_feed->GetNextFeedURL(&next_feed_url); | 573 const bool has_next_feed_url = current_feed->GetNextFeedURL(&next_feed_url); |
| 583 | 574 |
| 584 #ifndef NDEBUG | 575 #ifndef NDEBUG |
| 585 // Save initial root feed for analysis. | 576 // Save initial root feed for analysis. |
| 586 std::string file_name = | 577 std::string file_name = |
| 587 base::StringPrintf("DEBUG_feed_%" PRId64 ".json", | 578 base::StringPrintf("DEBUG_feed_%" PRId64 ".json", |
| 588 params->start_changestamp); | 579 params->start_changestamp); |
| 589 util::PostBlockingPoolSequencedTask( | 580 util::PostBlockingPoolSequencedTask( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 params->should_fetch_multiple_feeds, | 635 params->should_fetch_multiple_feeds, |
| 645 params->search_file_path, | 636 params->search_file_path, |
| 646 params->search_query, | 637 params->search_query, |
| 647 params->directory_resource_id, | 638 params->directory_resource_id, |
| 648 params->callback, | 639 params->callback, |
| 649 params->ui_state.release())), | 640 params->ui_state.release())), |
| 650 start_time)); | 641 start_time)); |
| 651 return; | 642 return; |
| 652 } | 643 } |
| 653 | 644 |
| 654 // Notify the observers that a document feed is fetched. | 645 // Notify the observers that all document feeds are fetched. |
| 655 FOR_EACH_OBSERVER(Observer, observers_, | 646 FOR_EACH_OBSERVER(Observer, observers_, |
| 656 OnDocumentFeedFetched(num_accumulated_entries)); | 647 OnDocumentFeedFetched(num_accumulated_entries)); |
| 657 | 648 |
| 658 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime", | 649 UMA_HISTOGRAM_TIMES("Gdata.EntireFeedLoadTime", |
| 659 base::TimeTicks::Now() - start_time); | 650 base::TimeTicks::Now() - start_time); |
| 660 | 651 |
| 661 if (!callback.is_null()) | 652 // Run the callback so the client can process the retrieved feeds. |
| 662 callback.Run(params, error); | 653 callback.Run(params, error); |
| 663 } | 654 } |
| 664 | 655 |
| 665 void GDataWapiFeedLoader::OnGetChangelist( | 656 void GDataWapiFeedLoader::OnGetChangelist( |
| 666 ContentOrigin initial_origin, | 657 ContentOrigin initial_origin, |
| 667 const LoadDocumentFeedCallback& callback, | 658 const LoadDocumentFeedCallback& callback, |
| 668 GetDocumentsParams* params, | 659 GetDocumentsParams* params, |
| 669 base::TimeTicks start_time, | 660 base::TimeTicks start_time, |
| 670 GDataErrorCode status, | 661 GDataErrorCode status, |
| 671 scoped_ptr<base::Value> data) { | 662 scoped_ptr<base::Value> data) { |
| 672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 664 DCHECK(!callback.is_null()); | |
| 673 | 665 |
| 674 if (params->feed_list->empty()) { | 666 if (params->feed_list->empty()) { |
| 675 UMA_HISTOGRAM_TIMES("Drive.InitialFeedLoadTime", | 667 UMA_HISTOGRAM_TIMES("Drive.InitialFeedLoadTime", |
| 676 base::TimeTicks::Now() - start_time); | 668 base::TimeTicks::Now() - start_time); |
| 677 } | 669 } |
| 678 | 670 |
| 679 GDataFileError error = util::GDataToGDataFileError(status); | 671 GDataFileError error = util::GDataToGDataFileError(status); |
| 680 if (error == GDATA_FILE_OK && | 672 if (error == GDATA_FILE_OK && |
| 681 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) { | 673 (!data.get() || data->GetType() != Value::TYPE_DICTIONARY)) { |
| 682 error = GDATA_FILE_ERROR_FAILED; | 674 error = GDATA_FILE_ERROR_FAILED; |
| 683 } | 675 } |
| 684 | 676 |
| 685 if (error != GDATA_FILE_OK) { | 677 if (error != GDATA_FILE_OK) { |
| 686 directory_service_->set_origin(initial_origin); | 678 directory_service_->set_origin(initial_origin); |
| 687 | 679 callback.Run(params, error); |
| 688 if (!callback.is_null()) | |
| 689 callback.Run(params, error); | |
| 690 | |
| 691 return; | 680 return; |
| 692 } | 681 } |
| 693 | 682 |
| 694 GURL next_feed_url; | 683 GURL next_feed_url; |
| 695 scoped_ptr<ChangeList> current_feed(ChangeList::CreateFrom(*data)); | 684 scoped_ptr<ChangeList> current_feed(ChangeList::CreateFrom(*data)); |
| 696 if (!current_feed.get()) { | 685 if (!current_feed.get()) { |
| 697 if (!callback.is_null()) { | 686 callback.Run(params, GDATA_FILE_ERROR_FAILED); |
| 698 callback.Run(params, GDATA_FILE_ERROR_FAILED); | |
| 699 } | |
| 700 return; | 687 return; |
| 701 } | 688 } |
| 702 const bool has_next_feed = !current_feed->next_page_token().empty(); | 689 const bool has_next_feed = !current_feed->next_page_token().empty(); |
| 703 | 690 |
| 704 #ifndef NDEBUG | 691 #ifndef NDEBUG |
| 705 // Save initial root feed for analysis. | 692 // Save initial root feed for analysis. |
| 706 std::string file_name = | 693 std::string file_name = |
| 707 base::StringPrintf("DEBUG_changelist_%" PRId64 ".json", | 694 base::StringPrintf("DEBUG_changelist_%" PRId64 ".json", |
| 708 params->start_changestamp); | 695 params->start_changestamp); |
| 709 util::PostBlockingPoolSequencedTask( | 696 util::PostBlockingPoolSequencedTask( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 params->should_fetch_multiple_feeds, | 751 params->should_fetch_multiple_feeds, |
| 765 params->search_file_path, | 752 params->search_file_path, |
| 766 params->search_query, | 753 params->search_query, |
| 767 params->directory_resource_id, | 754 params->directory_resource_id, |
| 768 params->callback, | 755 params->callback, |
| 769 NULL)), | 756 NULL)), |
| 770 start_time)); | 757 start_time)); |
| 771 return; | 758 return; |
| 772 } | 759 } |
| 773 | 760 |
| 774 // Notify the observers that a document feed is fetched. | 761 // Notify the observers that all document feeds are fetched. |
| 775 FOR_EACH_OBSERVER(Observer, observers_, | 762 FOR_EACH_OBSERVER(Observer, observers_, |
| 776 OnDocumentFeedFetched(num_accumulated_entries)); | 763 OnDocumentFeedFetched(num_accumulated_entries)); |
| 777 | 764 |
| 778 UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime", | 765 UMA_HISTOGRAM_TIMES("Drive.EntireFeedLoadTime", |
| 779 base::TimeTicks::Now() - start_time); | 766 base::TimeTicks::Now() - start_time); |
| 780 | 767 |
| 781 if (!callback.is_null()) | 768 // Run the callback so the client can process the retrieved feeds. |
| 782 callback.Run(params, error); | 769 callback.Run(params, error); |
| 783 } | 770 } |
| 784 | 771 |
| 785 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( | 772 void GDataWapiFeedLoader::OnNotifyDocumentFeedFetched( |
| 786 base::WeakPtr<GetDocumentsUiState> ui_state) { | 773 base::WeakPtr<GetDocumentsUiState> ui_state) { |
| 787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 774 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 788 | 775 |
| 789 if (!ui_state) { | 776 if (!ui_state) { |
| 790 // The ui state instance is already released, which means the fetching | 777 // The ui state instance is already released, which means the fetching |
| 791 // is done and we don't need to update any more. | 778 // is done and we don't need to update any more. |
| 792 return; | 779 return; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 815 weak_ptr_factory_.GetWeakPtr(), | 802 weak_ptr_factory_.GetWeakPtr(), |
| 816 ui_state->weak_ptr_factory.GetWeakPtr()), | 803 ui_state->weak_ptr_factory.GetWeakPtr()), |
| 817 remaining_duration / num_remaining_ui_updates); | 804 remaining_duration / num_remaining_ui_updates); |
| 818 } | 805 } |
| 819 } | 806 } |
| 820 } | 807 } |
| 821 | 808 |
| 822 void GDataWapiFeedLoader::LoadFromCache( | 809 void GDataWapiFeedLoader::LoadFromCache( |
| 823 bool should_load_from_server, | 810 bool should_load_from_server, |
| 824 const FilePath& search_file_path, | 811 const FilePath& search_file_path, |
| 825 const FindEntryCallback& callback) { | 812 const FileOperationCallback& callback) { |
| 826 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 827 | 814 |
| 828 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, | 815 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, |
| 829 should_load_from_server, | 816 should_load_from_server, |
| 830 callback); | 817 callback); |
| 831 FilePath path = cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META); | 818 FilePath path = cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META); |
| 832 if (UseLevelDB()) { | 819 if (UseLevelDB()) { |
| 833 path = path.Append(kResourceMetadataDBFile); | 820 path = path.Append(kResourceMetadataDBFile); |
| 834 directory_service_->InitFromDB(path, blocking_task_runner_, | 821 directory_service_->InitFromDB(path, blocking_task_runner_, |
| 835 base::Bind( | 822 base::Bind( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 | 858 |
| 872 void GDataWapiFeedLoader::ContinueWithInitializedDirectoryService( | 859 void GDataWapiFeedLoader::ContinueWithInitializedDirectoryService( |
| 873 LoadRootFeedParams* params, | 860 LoadRootFeedParams* params, |
| 874 GDataFileError error) { | 861 GDataFileError error) { |
| 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 876 | 863 |
| 877 DVLOG(1) << "Time elapsed to load directory service from disk=" | 864 DVLOG(1) << "Time elapsed to load directory service from disk=" |
| 878 << (base::Time::Now() - params->load_start_time).InMilliseconds() | 865 << (base::Time::Now() - params->load_start_time).InMilliseconds() |
| 879 << " milliseconds"; | 866 << " milliseconds"; |
| 880 | 867 |
| 881 FindEntryCallback callback = params->callback; | 868 FileOperationCallback callback = params->callback; |
|
achuithb
2012/08/14 23:57:36
This callback code is a bit difficult to follow.
achuithb
2012/08/15 00:13:15
ping
satorux1
2012/08/15 00:26:29
Oops, missed this. Fully agree it's hard to follow
achuithb
2012/08/15 00:42:33
Could you please add a TODO in this CL?
satorux1
2012/08/15 01:26:23
Done.
| |
| 882 // If we got feed content from cache, try search over it. | 869 // If we got feed content from cache, tell the client that the loading was |
| 870 // successful. | |
| 883 if (error == GDATA_FILE_OK && !callback.is_null()) { | 871 if (error == GDATA_FILE_OK && !callback.is_null()) { |
| 884 // Continue file content search operation if the delegate hasn't terminated | 872 callback.Run(GDATA_FILE_OK); |
| 885 // this search branch already. | 873 // Reset the callback so we don't run the same callback once |
| 886 directory_service_->FindEntryByPathAndRunSync(params->search_file_path, | 874 // ReloadFeedFromServerIfNeeded() is complete. |
| 887 callback); | |
| 888 callback.Reset(); | 875 callback.Reset(); |
| 889 } | 876 } |
| 890 | 877 |
| 891 if (!params->should_load_from_server) | 878 if (!params->should_load_from_server) |
| 892 return; | 879 return; |
| 893 | 880 |
| 894 // Decide the |initial_origin| to pass to ReloadFromServerIfNeeded(). | 881 // Decide the |initial_origin| to pass to ReloadFromServerIfNeeded(). |
| 895 // This is used to restore directory content origin to its initial value when | 882 // This is used to restore directory content origin to its initial value when |
| 896 // we fail to retrieve the feed from server. | 883 // we fail to retrieve the feed from server. |
| 897 // By default, if directory content is not yet initialized, restore content | 884 // By default, if directory content is not yet initialized, restore content |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 dir_iter != changed_dirs.end(); ++dir_iter) { | 950 dir_iter != changed_dirs.end(); ++dir_iter) { |
| 964 FOR_EACH_OBSERVER(Observer, observers_, | 951 FOR_EACH_OBSERVER(Observer, observers_, |
| 965 OnDirectoryChanged(*dir_iter)); | 952 OnDirectoryChanged(*dir_iter)); |
| 966 } | 953 } |
| 967 } | 954 } |
| 968 | 955 |
| 969 return error; | 956 return error; |
| 970 } | 957 } |
| 971 | 958 |
| 972 } // namespace gdata | 959 } // namespace gdata |
| OLD | NEW |