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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, |
252 weak_ptr_factory_.GetWeakPtr(), | 252 weak_ptr_factory_.GetWeakPtr(), |
253 initial_origin, | 253 initial_origin, |
254 local_changestamp, | 254 local_changestamp, |
255 search_file_path, | 255 search_file_path, |
256 callback)); | 256 callback)); |
| 257 // Drive v2 needs a separate application list fetch operation. |
| 258 // TODO(kochi): Application list rarely changes and do not necessarily |
| 259 // refresed as often as files. |
| 260 documents_service_->GetApplicationList( |
| 261 base::Bind(&GDataWapiFeedLoader::OnGetApplicationList, |
| 262 weak_ptr_factory_.GetWeakPtr())); |
257 return; | 263 return; |
258 } | 264 } |
259 | 265 |
260 documents_service_->GetAccountMetadata( | 266 documents_service_->GetAccountMetadata( |
261 base::Bind(&GDataWapiFeedLoader::OnGetAccountMetadata, | 267 base::Bind(&GDataWapiFeedLoader::OnGetAccountMetadata, |
262 weak_ptr_factory_.GetWeakPtr(), | 268 weak_ptr_factory_.GetWeakPtr(), |
263 initial_origin, | 269 initial_origin, |
264 local_changestamp, | 270 local_changestamp, |
265 search_file_path, | 271 search_file_path, |
266 callback)); | 272 callback)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 search_file_path, | 320 search_file_path, |
315 std::string() /* no search query */, | 321 std::string() /* no search query */, |
316 GURL(), /* feed not explicitly set */ | 322 GURL(), /* feed not explicitly set */ |
317 std::string() /* no directory resource ID */, | 323 std::string() /* no directory resource ID */, |
318 callback, | 324 callback, |
319 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, | 325 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
320 weak_ptr_factory_.GetWeakPtr())); | 326 weak_ptr_factory_.GetWeakPtr())); |
321 return; | 327 return; |
322 } | 328 } |
323 | 329 |
324 webapps_registry_->UpdateFromFeed(account_metadata.get()); | 330 webapps_registry_->UpdateFromFeed(*account_metadata.get()); |
325 | 331 |
326 bool changes_detected = true; | 332 bool changes_detected = true; |
327 if (local_changestamp >= account_metadata->largest_changestamp()) { | 333 if (local_changestamp >= account_metadata->largest_changestamp()) { |
328 if (local_changestamp > account_metadata->largest_changestamp()) { | 334 if (local_changestamp > account_metadata->largest_changestamp()) { |
329 LOG(WARNING) << "Cached client feed is fresher than server, client = " | 335 LOG(WARNING) << "Cached client feed is fresher than server, client = " |
330 << local_changestamp | 336 << local_changestamp |
331 << ", server = " | 337 << ", server = " |
332 << account_metadata->largest_changestamp(); | 338 << account_metadata->largest_changestamp(); |
333 } | 339 } |
334 // If our cache holds the latest state from the server, change the | 340 // If our cache holds the latest state from the server, change the |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 true, /* should_fetch_multiple_feeds */ | 444 true, /* should_fetch_multiple_feeds */ |
439 search_file_path, | 445 search_file_path, |
440 std::string() /* no search query */, | 446 std::string() /* no search query */, |
441 GURL(), /* feed not explicitly set */ | 447 GURL(), /* feed not explicitly set */ |
442 std::string() /* no directory resource ID */, | 448 std::string() /* no directory resource ID */, |
443 callback, | 449 callback, |
444 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, | 450 base::Bind(&GDataWapiFeedLoader::OnFeedFromServerLoaded, |
445 weak_ptr_factory_.GetWeakPtr())); | 451 weak_ptr_factory_.GetWeakPtr())); |
446 } | 452 } |
447 | 453 |
| 454 void GDataWapiFeedLoader::OnGetApplicationList( |
| 455 GDataErrorCode status, |
| 456 scoped_ptr<base::Value> json) { |
| 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 458 |
| 459 GDataFileError error = util::GDataToGDataFileError(status); |
| 460 if (error != GDATA_FILE_OK) |
| 461 return; |
| 462 |
| 463 if (json.get()) { |
| 464 scoped_ptr<AppList> applist(AppList::CreateFrom(*json)); |
| 465 if (applist.get()) { |
| 466 VLOG(1) << "applist get success"; |
| 467 webapps_registry_->UpdateFromApplicationList(*applist.get()); |
| 468 } |
| 469 } |
| 470 } |
| 471 |
448 // TODO(kochi): Fix too many parameters. http://crbug.com/141359 | 472 // TODO(kochi): Fix too many parameters. http://crbug.com/141359 |
449 void GDataWapiFeedLoader::LoadFromServer( | 473 void GDataWapiFeedLoader::LoadFromServer( |
450 ContentOrigin initial_origin, | 474 ContentOrigin initial_origin, |
451 int64 start_changestamp, | 475 int64 start_changestamp, |
452 int64 root_feed_changestamp, | 476 int64 root_feed_changestamp, |
453 bool should_fetch_multiple_feeds, | 477 bool should_fetch_multiple_feeds, |
454 const FilePath& search_file_path, | 478 const FilePath& search_file_path, |
455 const std::string& search_query, | 479 const std::string& search_query, |
456 const GURL& feed_to_load, | 480 const GURL& feed_to_load, |
457 const std::string& directory_resource_id, | 481 const std::string& directory_resource_id, |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 dir_iter != changed_dirs.end(); ++dir_iter) { | 987 dir_iter != changed_dirs.end(); ++dir_iter) { |
964 FOR_EACH_OBSERVER(Observer, observers_, | 988 FOR_EACH_OBSERVER(Observer, observers_, |
965 OnDirectoryChanged(*dir_iter)); | 989 OnDirectoryChanged(*dir_iter)); |
966 } | 990 } |
967 } | 991 } |
968 | 992 |
969 return error; | 993 return error; |
970 } | 994 } |
971 | 995 |
972 } // namespace gdata | 996 } // namespace gdata |
OLD | NEW |