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

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

Issue 9836086: Added logic that will return the result of the first chunk of root feed and continue fetching the r… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 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_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after
1449 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, FilePath(), 1449 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, FilePath(),
1450 reinterpret_cast<GDataFileBase*>(NULL))); 1450 reinterpret_cast<GDataFileBase*>(NULL)));
1451 } 1451 }
1452 1452
1453 return; 1453 return;
1454 } 1454 }
1455 1455
1456 // Add the current feed to the list of collected feeds for this directory. 1456 // Add the current feed to the list of collected feeds for this directory.
1457 feed_list->Append(data.release()); 1457 feed_list->Append(data.release());
1458 1458
1459 // Check if we need to collect more data to complete the directory list. 1459 bool initial_read = false;
1460 if (current_feed->GetNextFeedURL(&next_feed_url) && 1460 {
1461 !next_feed_url.is_empty()) { 1461 base::AutoLock lock(lock_);
1462 initial_read = root_->origin() == UNINITIALIZED;
1463 }
1464
1465 bool has_more_data = current_feed->GetNextFeedURL(&next_feed_url) &&
1466 !next_feed_url.is_empty();
1467
1468 // If we are completely done with feed content fetching or if this is initial
1469 // batch of content feed, we might want to update |root_| content and report
satorux1 2012/03/25 17:28:27 nit: to make it very clear, we might want to descr
zel 2012/03/25 17:39:20 Done.
1470 // on it.
1471 if (initial_read || !has_more_data) {
1472 error = UpdateDirectoryWithDocumentFeed(feed_list.get(),
1473 FROM_SERVER);
1474 if (error != base::PLATFORM_FILE_OK) {
1475 if (!callback.is_null()) {
1476 proxy->PostTask(FROM_HERE,
1477 base::Bind(callback, error, FilePath(),
1478 reinterpret_cast<GDataFileBase*>(NULL)));
1479 }
1480
1481 return;
1482 }
1483
1484 // If we had someone to report this too, then this retrieval was done in a
1485 // context of search... so continue search.
1486 if (!callback.is_null()) {
1487 proxy->PostTask(FROM_HERE,
1488 base::Bind(&GDataFileSystem::FindFileByPathOnCallingThread,
1489 GetWeakPtrForCurrentThread(),
1490 search_file_path,
1491 callback));
1492 }
1493 }
1494
1495 if (has_more_data) {
1496 // Don't report to initial callback if we were fetching the first chunk of
1497 // uninitialized root feed, because we already reported. Instead, just
1498 // continue with entire feed fetch in backgorund.
1499 const FindFileCallback continue_callback =
1500 initial_read ? FindFileCallback() : callback;
1462 // Kick of the remaining part of the feeds. 1501 // Kick of the remaining part of the feeds.
1463 documents_service_->GetDocuments( 1502 documents_service_->GetDocuments(
1464 next_feed_url, 1503 next_feed_url,
1465 base::Bind(&GDataFileSystem::OnGetDocuments, 1504 base::Bind(&GDataFileSystem::OnGetDocuments,
1466 GetWeakPtrForCurrentThread(), 1505 GetWeakPtrForCurrentThread(),
1467 search_file_path, 1506 search_file_path,
1468 base::Passed(&feed_list), 1507 base::Passed(&feed_list),
1469 proxy, 1508 proxy,
1470 callback)); 1509 continue_callback));
1471 return; 1510 } else {
1472 } 1511 // Save completed feed in meta cache.
1473 1512 scoped_ptr<base::Value> feed_list_value(feed_list.release());
1474 error = UpdateDirectoryWithDocumentFeed(feed_list.get(), FROM_SERVER); 1513 SaveFeed(feed_list_value.Pass(), FilePath(kLastFeedFile));
1475 if (error != base::PLATFORM_FILE_OK) {
1476 if (!callback.is_null()) {
1477 proxy->PostTask(FROM_HERE,
1478 base::Bind(callback, error, FilePath(),
1479 reinterpret_cast<GDataFileBase*>(NULL)));
1480 }
1481
1482 return;
1483 }
1484
1485 scoped_ptr<base::Value> feed_list_value(feed_list.release());
1486 SaveFeed(feed_list_value.Pass(), FilePath(kLastFeedFile));
1487
1488 // If we had someone to report this too, then this retrieval was done in a
1489 // context of search... so continue search.
1490 if (!callback.is_null()) {
1491 proxy->PostTask(FROM_HERE,
1492 base::Bind(&GDataFileSystem::FindFileByPathOnCallingThread,
1493 GetWeakPtrForCurrentThread(),
1494 search_file_path,
1495 callback));
1496 } 1514 }
1497 } 1515 }
1498 1516
1499 void GDataFileSystem::LoadRootFeedFromCache( 1517 void GDataFileSystem::LoadRootFeedFromCache(
1500 const FilePath& search_file_path, 1518 const FilePath& search_file_path,
1501 bool load_from_server, 1519 bool load_from_server,
1502 scoped_refptr<base::MessageLoopProxy> proxy, 1520 scoped_refptr<base::MessageLoopProxy> proxy,
1503 const FindFileCallback& callback) { 1521 const FindFileCallback& callback) {
1504 BrowserThread::PostBlockingPoolTask(FROM_HERE, 1522 BrowserThread::PostBlockingPoolTask(FROM_HERE,
1505 base::Bind(&GDataFileSystem::LoadRootFeedOnIOThreadPool, 1523 base::Bind(&GDataFileSystem::LoadRootFeedOnIOThreadPool,
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 GURL parent_url; 1970 GURL parent_url;
1953 const Link* parent_link = doc->GetLinkByType(Link::PARENT); 1971 const Link* parent_link = doc->GetLinkByType(Link::PARENT);
1954 if (parent_link) 1972 if (parent_link)
1955 parent_url = parent_link->href(); 1973 parent_url = parent_link->href();
1956 1974
1957 UrlToFileAndParentMap::mapped_type& map_entry = 1975 UrlToFileAndParentMap::mapped_type& map_entry =
1958 file_by_url[file->self_url()]; 1976 file_by_url[file->self_url()];
1959 // An entry with the same self link may already exist, so we need to 1977 // An entry with the same self link may already exist, so we need to
1960 // release the existing GDataFileBase instance before overwriting the 1978 // release the existing GDataFileBase instance before overwriting the
1961 // entry with another GDataFileBase instance. 1979 // entry with another GDataFileBase instance.
1980 if (map_entry.first) {
1981 LOG(WARNING) << "Found duplicate file "
1982 << map_entry.first->file_name();
1983 }
1984
1962 delete map_entry.first; 1985 delete map_entry.first;
1963 map_entry.first = file; 1986 map_entry.first = file;
1964 map_entry.second = parent_url; 1987 map_entry.second = parent_url;
1965 } 1988 }
1966 } 1989 }
1967 1990
1968 if (error != base::PLATFORM_FILE_OK) { 1991 if (error != base::PLATFORM_FILE_OK) {
1969 // If the code above fails to parse a feed, any GDataFileBase instance 1992 // If the code above fails to parse a feed, any GDataFileBase instance
1970 // added to |file_by_url| is not managed by a GDataDirectory instance, 1993 // added to |file_by_url| is not managed by a GDataDirectory instance,
1971 // so we need to explicitly release them here. 1994 // so we need to explicitly release them here.
1972 for (UrlToFileAndParentMap::iterator it = file_by_url.begin(); 1995 for (UrlToFileAndParentMap::iterator it = file_by_url.begin();
1973 it != file_by_url.end(); ++it) { 1996 it != file_by_url.end(); ++it) {
1974 delete it->second.first; 1997 delete it->second.first;
1975 } 1998 }
1976 return error; 1999 return error;
1977 } 2000 }
1978 2001
2002 scoped_ptr<GDataRootDirectory> orphaned_files(new GDataRootDirectory(NULL));
1979 for (UrlToFileAndParentMap::iterator it = file_by_url.begin(); 2003 for (UrlToFileAndParentMap::iterator it = file_by_url.begin();
1980 it != file_by_url.end(); ++it) { 2004 it != file_by_url.end(); ++it) {
1981 scoped_ptr<GDataFileBase> file(it->second.first); 2005 scoped_ptr<GDataFileBase> file(it->second.first);
1982 GURL parent_url = it->second.second; 2006 GURL parent_url = it->second.second;
1983 GDataDirectory* dir = root_.get(); 2007 GDataDirectory* dir = root_.get();
1984 if (!parent_url.is_empty()) { 2008 if (!parent_url.is_empty()) {
1985 UrlToFileAndParentMap::iterator find_iter = file_by_url.find(parent_url); 2009 UrlToFileAndParentMap::const_iterator find_iter =
2010 file_by_url.find(parent_url);
1986 if (find_iter == file_by_url.end()) { 2011 if (find_iter == file_by_url.end()) {
1987 LOG(WARNING) << "Found orphaned file '" << file->file_name() 2012 DVLOG(1) << "Found orphaned file '" << file->file_name()
1988 << "' with non-existing parent folder of " 2013 << "' with non-existing parent folder of "
1989 << parent_url.spec(); 2014 << parent_url.spec();
2015 dir = orphaned_files.get();
1990 } else { 2016 } else {
1991 dir = find_iter->second.first->AsGDataDirectory(); 2017 dir = find_iter->second.first ?
2018 find_iter->second.first->AsGDataDirectory() : NULL;
1992 if (!dir) { 2019 if (!dir) {
1993 LOG(WARNING) << "Found orphaned file '" << file->file_name() 2020 DVLOG(1) << "Found orphaned file '" << file->file_name()
1994 << "' pointing to non directory parent " 2021 << "' pointing to non directory parent "
1995 << parent_url.spec(); 2022 << parent_url.spec();
1996 dir = root_.get(); 2023 dir = orphaned_files.get();
1997 } 2024 }
1998 } 2025 }
1999 } 2026 }
2000 DCHECK(dir);
2001
2002 dir->AddFile(file.release()); 2027 dir->AddFile(file.release());
2003 } 2028 }
2004 2029
2005 if (should_nofify) 2030 if (should_nofify)
2006 NotifyDirectoryChanged(root_->GetFilePath()); 2031 NotifyDirectoryChanged(root_->GetFilePath());
2007 2032
2008 return base::PLATFORM_FILE_OK; 2033 return base::PLATFORM_FILE_OK;
2009 } 2034 }
2010 2035
2011 void GDataFileSystem::NotifyCacheInitialized() { 2036 void GDataFileSystem::NotifyCacheInitialized() {
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
3317 const bool posted = BrowserThread::PostBlockingPoolSequencedTask( 3342 const bool posted = BrowserThread::PostBlockingPoolSequencedTask(
3318 sequence_token_name, 3343 sequence_token_name,
3319 from_here, 3344 from_here,
3320 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool, 3345 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool,
3321 base::Unretained(this), 3346 base::Unretained(this),
3322 task)); 3347 task));
3323 DCHECK(posted); 3348 DCHECK(posted);
3324 } 3349 }
3325 3350
3326 } // namespace gdata 3351 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698