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

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: crash fix 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 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, FilePath(), 1448 base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED, FilePath(),
1449 reinterpret_cast<GDataFileBase*>(NULL))); 1449 reinterpret_cast<GDataFileBase*>(NULL)));
1450 } 1450 }
1451 1451
1452 return; 1452 return;
1453 } 1453 }
1454 1454
1455 // Add the current feed to the list of collected feeds for this directory. 1455 // Add the current feed to the list of collected feeds for this directory.
1456 feed_list->Append(data.release()); 1456 feed_list->Append(data.release());
1457 1457
1458 // Check if we need to collect more data to complete the directory list. 1458 bool inital_read = false;
satorux1 2012/03/25 00:22:26 nit: initial
zel 2012/03/25 02:06:41 Done.
1459 if (current_feed->GetNextFeedURL(&next_feed_url) && 1459 {
1460 !next_feed_url.is_empty()) { 1460 base::AutoLock lock(lock_);
1461 inital_read = root_->origin() == UNINITIALIZED;
1462 }
1463
1464 bool has_more_data = current_feed->GetNextFeedURL(&next_feed_url) &&
1465 !next_feed_url.is_empty();
1466
1467 if (!has_more_data || inital_read) {
satorux1 2012/03/25 00:22:26 nit: make the order consistent with the code above
zel 2012/03/25 02:06:41 Done.
1468 error = UpdateDirectoryWithDocumentFeed(feed_list.get(),
1469 FROM_SERVER);
1470 if (error != base::PLATFORM_FILE_OK) {
1471 if (!callback.is_null()) {
1472 proxy->PostTask(FROM_HERE,
1473 base::Bind(callback, error, FilePath(),
1474 reinterpret_cast<GDataFileBase*>(NULL)));
1475 }
1476
1477 return;
1478 }
1479
1480 // If we had someone to report this too, then this retrieval was done in a
1481 // context of search... so continue search.
1482 if (!callback.is_null()) {
1483 proxy->PostTask(FROM_HERE,
1484 base::Bind(&GDataFileSystem::FindFileByPathOnCallingThread,
1485 GetWeakPtrForCurrentThread(),
1486 search_file_path,
1487 callback));
1488 }
1489 }
1490
1491 if (has_more_data) {
1492 // Don't report to initial callback if we were fetching the first chunk of
1493 // uninitialized root feed. Instead, just continue with entire feed fetch
satorux1 2012/03/25 00:22:26 // uninitialized root feed. -> // uninitialized ro
zel 2012/03/25 02:06:41 Done.
1494 // in backgorund.
1495 const FindFileCallback continue_callback =
1496 inital_read ? FindFileCallback() : callback;
satorux1 2012/03/25 00:22:26 So we won't call the callback when the last chunk
zel 2012/03/25 02:06:41 The callback that returns results of find operatio
1461 // Kick of the remaining part of the feeds. 1497 // Kick of the remaining part of the feeds.
1462 documents_service_->GetDocuments( 1498 documents_service_->GetDocuments(
1463 next_feed_url, 1499 next_feed_url,
1464 base::Bind(&GDataFileSystem::OnGetDocuments, 1500 base::Bind(&GDataFileSystem::OnGetDocuments,
1465 GetWeakPtrForCurrentThread(), 1501 GetWeakPtrForCurrentThread(),
1466 search_file_path, 1502 search_file_path,
1467 base::Passed(&feed_list), 1503 base::Passed(&feed_list),
1468 proxy, 1504 proxy,
1469 callback)); 1505 continue_callback));
1470 return; 1506 } else {
1471 } 1507 // Save completed feed in meta cache.
1472 1508 scoped_ptr<base::Value> feed_list_value(feed_list.release());
1473 error = UpdateDirectoryWithDocumentFeed(feed_list.get(), FROM_SERVER); 1509 SaveFeed(feed_list_value.Pass(), FilePath(kLastFeedFile));
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 scoped_ptr<base::Value> feed_list_value(feed_list.release());
1485 SaveFeed(feed_list_value.Pass(), FilePath(kLastFeedFile));
1486
1487 // If we had someone to report this too, then this retrieval was done in a
1488 // context of search... so continue search.
1489 if (!callback.is_null()) {
1490 proxy->PostTask(FROM_HERE,
1491 base::Bind(&GDataFileSystem::FindFileByPathOnCallingThread,
1492 GetWeakPtrForCurrentThread(),
1493 search_file_path,
1494 callback));
1495 } 1510 }
1496 } 1511 }
1497 1512
1498 void GDataFileSystem::LoadRootFeedFromCache( 1513 void GDataFileSystem::LoadRootFeedFromCache(
1499 const FilePath& search_file_path, 1514 const FilePath& search_file_path,
1500 bool load_from_server, 1515 bool load_from_server,
1501 scoped_refptr<base::MessageLoopProxy> proxy, 1516 scoped_refptr<base::MessageLoopProxy> proxy,
1502 const FindFileCallback& callback) { 1517 const FindFileCallback& callback) {
1503 BrowserThread::PostBlockingPoolTask(FROM_HERE, 1518 BrowserThread::PostBlockingPoolTask(FROM_HERE,
1504 base::Bind(&GDataFileSystem::LoadRootFeedOnIOThreadPool, 1519 base::Bind(&GDataFileSystem::LoadRootFeedOnIOThreadPool,
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 // If the code above fails to parse a feed, any GDataFileBase instance 1989 // If the code above fails to parse a feed, any GDataFileBase instance
1975 // added to |file_by_url| is not managed by a GDataDirectory instance, 1990 // added to |file_by_url| is not managed by a GDataDirectory instance,
1976 // so we need to explicitly release them here. 1991 // so we need to explicitly release them here.
1977 for (UrlToFileAndParentMap::iterator it = file_by_url.begin(); 1992 for (UrlToFileAndParentMap::iterator it = file_by_url.begin();
1978 it != file_by_url.end(); ++it) { 1993 it != file_by_url.end(); ++it) {
1979 delete it->second.first; 1994 delete it->second.first;
1980 } 1995 }
1981 return error; 1996 return error;
1982 } 1997 }
1983 1998
1999 scoped_ptr<GDataRootDirectory> orphans(new GDataRootDirectory(NULL));
satorux1 2012/03/25 00:22:26 This part doesn't seem to be related to the direct
zel 2012/03/25 02:06:41 Done.
zel 2012/03/25 03:22:10 My unit tests convinced me that this on was still
1984 for (UrlToFileAndParentMap::iterator it = file_by_url.begin(); 2000 for (UrlToFileAndParentMap::iterator it = file_by_url.begin();
1985 it != file_by_url.end(); ++it) { 2001 it != file_by_url.end(); ++it) {
1986 scoped_ptr<GDataFileBase> file(it->second.first); 2002 scoped_ptr<GDataFileBase> file(it->second.first);
1987 GURL parent_url = it->second.second; 2003 GURL parent_url = it->second.second;
1988 GDataDirectory* dir = root_.get(); 2004 GDataDirectory* dir = root_.get();
1989 if (!parent_url.is_empty()) { 2005 if (!parent_url.is_empty()) {
1990 UrlToFileAndParentMap::iterator find_iter = file_by_url.find(parent_url); 2006 UrlToFileAndParentMap::const_iterator find_iter =
2007 file_by_url.find(parent_url);
1991 if (find_iter == file_by_url.end()) { 2008 if (find_iter == file_by_url.end()) {
1992 LOG(WARNING) << "Found orphaned file '" << file->file_name() 2009 DVLOG(1) << "Found orphaned kitten file '" << file->file_name()
satorux1 2012/03/25 00:22:26 Does "kitten file" mean files shared by someone el
zel 2012/03/25 02:06:41 These are files that have parents that don't belon
1993 << "' with non-existing parent folder of " 2010 << "' with non-existing parent folder of "
1994 << parent_url.spec(); 2011 << parent_url.spec();
2012 dir = NULL;
1995 } else { 2013 } else {
1996 dir = find_iter->second.first->AsGDataDirectory(); 2014 dir = find_iter->second.first ?
2015 find_iter->second.first->AsGDataDirectory() : NULL;
1997 if (!dir) { 2016 if (!dir) {
1998 LOG(WARNING) << "Found orphaned file '" << file->file_name() 2017 DVLOG(1) << "Found orphaned file '" << file->file_name()
1999 << "' pointing to non directory parent " 2018 << "' pointing to non directory parent "
2000 << parent_url.spec(); 2019 << parent_url.spec();
2001 dir = root_.get(); 2020 dir = NULL;
2002 } 2021 }
2003 } 2022 }
2004 } 2023 }
2005 DCHECK(dir); 2024 if (dir)
2025 dir->AddFile(file.release());
2006 2026
2007 dir->AddFile(file.release()); 2027 // |file| instance is gone now, deleted by either this scoped_ptr (orphans)
satorux1 2012/03/25 00:22:26 I'm confused. |orphans| doesn't seem to be used to
zel 2012/03/25 02:06:41 orphans was supposed to be removed. done.
2028 // or taken over by |dir|. So, let's mark it as deleted in the map so we
2029 // don't end up with other children file items of this instance trying to
2030 // add themselves as chikdren.
satorux1 2012/03/25 00:22:26 children
zel 2012/03/25 02:06:41 Done.
2031 it->second.first = NULL;
2008 } 2032 }
2009 2033
2010 if (should_nofify) 2034 if (should_nofify)
2011 NotifyDirectoryChanged(root_->GetFilePath()); 2035 NotifyDirectoryChanged(root_->GetFilePath());
2012 2036
2013 return base::PLATFORM_FILE_OK; 2037 return base::PLATFORM_FILE_OK;
2014 } 2038 }
2015 2039
2016 void GDataFileSystem::NotifyCacheInitialized() { 2040 void GDataFileSystem::NotifyCacheInitialized() {
2017 DVLOG(1) << "Cache initialized"; 2041 DVLOG(1) << "Cache initialized";
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
3322 const bool posted = BrowserThread::PostBlockingPoolSequencedTask( 3346 const bool posted = BrowserThread::PostBlockingPoolSequencedTask(
3323 sequence_token_name, 3347 sequence_token_name,
3324 from_here, 3348 from_here,
3325 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool, 3349 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool,
3326 base::Unretained(this), 3350 base::Unretained(this),
3327 task)); 3351 task));
3328 DCHECK(posted); 3352 DCHECK(posted);
3329 } 3353 }
3330 3354
3331 } // namespace gdata 3355 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698