Commit 54261146 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Revert 152328 - Drive: Removes unused cache files after the initial feed fetch.

r152328 seems to cause the memorybot failure. See http://crbug.com/143715.

BUG=128088
TEST=manual
TBR=ben@chromium.org
# for chrome/chrome_browser.gypi (adding stale_cache_files_remover.[cc|h])

Review URL: https://chromiumcodereview.appspot.com/10832241

TBR=yoshiki@chromium.org

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152349 0039d316-1c4b-4281-b951-d872f2087c98
parent a87edf63
......@@ -26,7 +26,6 @@
#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
#include "chrome/browser/chromeos/gdata/gdata_uploader.h"
#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/chromeos/gdata/stale_cache_files_remover.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
......@@ -567,7 +566,6 @@ void GDataFileSystem::Initialize() {
cache_,
blocking_task_runner_));
feed_loader_->AddObserver(this);
stale_cache_files_remover_.reset(new StaleCacheFilesRemover(this, cache_));
PrefService* pref_service = profile_->GetPrefs();
hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
......
......@@ -34,7 +34,6 @@ class DocumentsServiceInterface;
class DriveWebAppsRegistryInterface;
class GDataUploaderInterface;
class GDataWapiFeedLoader;
class StaleCacheFilesRemover;
struct UploadFileInfo;
// The production implementation of GDataFileSystemInterface.
......@@ -843,9 +842,6 @@ class GDataFileSystem : public GDataFileSystemInterface,
// The loader is used to load the feeds.
scoped_ptr<GDataWapiFeedLoader> feed_loader_;
// The remover is used to remove stale cache files.
scoped_ptr<StaleCacheFilesRemover> stale_cache_files_remover_;
ObserverList<GDataFileSystemInterface::Observer> observers_;
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
......
......@@ -75,14 +75,6 @@ void DriveSearchCallback(
message_loop->Quit();
}
// Callback for GDataCache::StoreOnUIThread used in RemoveStaleCacheFiles test.
// Verifies that the result is not an error.
void VerifyCacheFileState(GDataFileError error,
const std::string& resource_id,
const std::string& md5) {
EXPECT_EQ(GDATA_FILE_OK, error);
}
// Action used to set mock expectations for
// DocumentsService::GetDocumentEntry().
ACTION_P2(MockGetDocumentEntry, status, value) {
......@@ -2651,48 +2643,4 @@ TEST_F(GDataFileSystemTest, OpenAndCloseFile) {
EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
}
TEST_F(GDataFileSystemTest, RemoveStaleCacheFiles) {
FilePath dummy_file = GetTestFilePath("root_feed.json");
std::string resource_id("pdf:1a2b");
std::string md5("abcdef0123456789");
EXPECT_CALL(*mock_free_disk_space_checker_, AmountOfFreeDiskSpace())
.Times(AtLeast(1)).WillRepeatedly(Return(kLotsOfSpace));
// Create a stale cache file.
cache_->StoreOnUIThread(resource_id, md5, dummy_file,
GDataCache::FILE_OPERATION_COPY,
base::Bind(&gdata::VerifyCacheFileState));
test_util::RunBlockingPoolTask();
// Verify that the cache file exists.
FilePath path = cache_->GetCacheFilePath(resource_id,
md5,
GDataCache::CACHE_TYPE_TMP,
GDataCache::CACHED_FILE_FROM_SERVER);
EXPECT_TRUE(file_util::PathExists(path));
// Verify that the corresponding file entry doesn't exist.
EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1);
EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _))
.Times(1);
EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
scoped_ptr<GDataEntryProto> entry = GetEntryInfoByPathSync(path);
ASSERT_FALSE(entry.get());
// Load a root feed.
LoadRootFeedDocument("root_feed.json");
// Wait for StaleCacheFilesRemover to finish cleaning up the stale file.
test_util::RunBlockingPoolTask();
// Verify that the cache file is deleted.
path = cache_->GetCacheFilePath(resource_id,
md5,
GDataCache::CACHE_TYPE_TMP,
GDataCache::CACHED_FILE_FROM_SERVER);
EXPECT_FALSE(file_util::PathExists(path));
}
} // namespace gdata
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/gdata/stale_cache_files_remover.h"
#include "base/bind.h"
#include "base/message_loop.h"
#include "chrome/browser/chromeos/gdata/gdata_cache.h"
#include "chrome/browser/chromeos/gdata/gdata_file_system.h"
#include "chrome/browser/chromeos/gdata/gdata.pb.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace gdata {
namespace {
// Emits the log when the remove failed.
void EmitErrorLog(GDataFileError error,
const std::string& resource_id,
const std::string& md5) {
if (error != gdata::GDATA_FILE_OK) {
LOG(WARNING) << "Failed to remove a stale cache file. resource_id:"
<< resource_id;
}
}
} // namespace
StaleCacheFilesRemover::StaleCacheFilesRemover(
GDataFileSystemInterface* file_system,
GDataCache* cache)
: file_system_(file_system),
cache_(cache),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
file_system_->AddObserver(this);
}
StaleCacheFilesRemover::~StaleCacheFilesRemover() {
file_system_->RemoveObserver(this);
}
void StaleCacheFilesRemover::OnInitialLoadFinished() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
const FilePath root_path = FilePath(gdata::kGDataRootDirectory);
cache_->GetResourceIdsOfAllFilesOnUIThread(
base::Bind(&StaleCacheFilesRemover::OnGetResourceIdsOfAllFiles,
weak_ptr_factory_.GetWeakPtr()));
}
void StaleCacheFilesRemover::OnGetResourceIdsOfAllFiles(
const std::vector<std::string>& resource_ids) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
for (size_t i = 0; i < resource_ids.size(); ++i) {
const std::string& resource_id = resource_ids[i];
cache_->GetCacheEntryOnUIThread(
resource_id,
"", // Don't check MD5.
base::Bind(
&StaleCacheFilesRemover::GetEntryInfoAndRemoveCacheIfNecessary,
weak_ptr_factory_.GetWeakPtr(),
resource_id));
}
}
void StaleCacheFilesRemover::GetEntryInfoAndRemoveCacheIfNecessary(
const std::string& resource_id,
bool success,
const gdata::GDataCacheEntry& cache_entry) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Removes the cache if GetCacheEntryOnUIThread() failed.
if (!success) {
LOG(WARNING) << "GetCacheEntryOnUIThread() failed";
return;
}
file_system_->GetEntryInfoByResourceId(
resource_id,
base::Bind(&StaleCacheFilesRemover::RemoveCacheIfNecessary,
weak_ptr_factory_.GetWeakPtr(),
resource_id,
cache_entry.md5()));
}
void StaleCacheFilesRemover::RemoveCacheIfNecessary(
const std::string& resource_id,
const std::string& cache_md5,
GDataFileError error,
const FilePath& gdata_file_path,
scoped_ptr<gdata::GDataEntryProto> entry_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// The entry is not found in the file system.
if (error != gdata::GDATA_FILE_OK) {
cache_->RemoveOnUIThread(resource_id, base::Bind(&EmitErrorLog));
return;
}
// The entry is found but the MD5 does not match.
DCHECK(entry_proto.get());
if (!entry_proto->has_file_specific_info() ||
cache_md5 != entry_proto->file_specific_info().file_md5()) {
cache_->RemoveOnUIThread(resource_id, base::Bind(&EmitErrorLog));
return;
}
}
} // namespace gdata
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_GDATA_STALE_CACHE_FILE_REMOVER_H_
#define CHROME_BROWSER_CHROMEOS_GDATA_STALE_CACHE_FILE_REMOVER_H_
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h"
namespace gdata{
class GDataCache;
class GDataFileSystem;
// This class removes stale cache files, which are present locally, but no
// longer present on the server. This can happen if files are removed from the
// server from other devices, or from the web interface.
class StaleCacheFilesRemover : public GDataFileSystemInterface::Observer {
public:
StaleCacheFilesRemover(GDataFileSystemInterface* file_system,
GDataCache* cache);
virtual ~StaleCacheFilesRemover();
private:
// Removes stale cache files.
// Gets the list of all the resource id and calls OnGetResourceIdsOfAllFiles()
// with the list.
virtual void OnInitialLoadFinished() OVERRIDE;
// Gets the cache entry of each resource id. And passes the cache entry to
// GetEntryInfoAndRemoveCacheIfNecessary().
void OnGetResourceIdsOfAllFiles(const std::vector<std::string>& resource_ids);
// Gets the file entry and calls RemoveCacheIfNecessary() with the file entry.
// This is called from StaleCacheFilesRemover::OnGetResourceIdsOfAllFiles().
void GetEntryInfoAndRemoveCacheIfNecessary(
const std::string& resource_id,
bool success,
const gdata::GDataCacheEntry& cache_entry);
// Check the cache file and removes if it is unavailable or invalid (eg. md5
// mismatch). This is called from GetCacheEntryAndRemoveCacheIfNecessary();
void RemoveCacheIfNecessary(
const std::string& resource_id,
const std::string& cache_md5,
GDataFileError error,
const FilePath& gdata_file_path,
scoped_ptr<gdata::GDataEntryProto> entry_proto);
GDataFileSystemInterface* file_system_; // Not owned.
GDataCache* cache_; // Not owned.
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<StaleCacheFilesRemover> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(StaleCacheFilesRemover);
};
} // namespace gdata
#endif // CHROME_BROWSER_CHROMEOS_GDATA_STALE_CACHE_FILE_REMOVER_H_
......@@ -614,8 +614,6 @@
'browser/chromeos/gdata/gdata_wapi_parser.h',
'browser/chromeos/gdata/operations_base.cc',
'browser/chromeos/gdata/operations_base.h',
'browser/chromeos/gdata/stale_cache_files_remover.cc',
'browser/chromeos/gdata/stale_cache_files_remover.h',
'browser/chromeos/gview_request_interceptor.cc',
'browser/chromeos/gview_request_interceptor.h',
'browser/chromeos/imageburner/burn_controller.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment