diff options
Diffstat (limited to 'chrome')
8 files changed, 301 insertions, 2 deletions
diff --git a/chrome/browser/chromeos/drive/file_system.cc b/chrome/browser/chromeos/drive/file_system.cc index e8e2a0e..975fbd5 100644 --- a/chrome/browser/chromeos/drive/file_system.cc +++ b/chrome/browser/chromeos/drive/file_system.cc @@ -420,8 +420,8 @@ void FileSystem::TouchFile(const base::FilePath& file_path, DCHECK(!last_modified_time.is_null()); DCHECK(!callback.is_null()); - // TODO(hidehiko): Implement this (crbug.com/144369). - NOTIMPLEMENTED(); + drive_operations_.TouchFile( + file_path, last_access_time, last_modified_time, callback); } void FileSystem::Pin(const base::FilePath& file_path, diff --git a/chrome/browser/chromeos/drive/file_system/drive_operations.cc b/chrome/browser/chromeos/drive/file_system/drive_operations.cc index 9eaef46..9a81b2e 100644 --- a/chrome/browser/chromeos/drive/file_system/drive_operations.cc +++ b/chrome/browser/chromeos/drive/file_system/drive_operations.cc @@ -11,6 +11,7 @@ #include "chrome/browser/chromeos/drive/file_system/move_operation.h" #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" #include "chrome/browser/chromeos/drive/file_system/search_operation.h" +#include "chrome/browser/chromeos/drive/file_system/touch_operation.h" #include "chrome/browser/chromeos/drive/file_system/update_operation.h" #include "content/public/browser/browser_thread.h" @@ -57,6 +58,8 @@ void DriveOperations::Init(OperationObserver* observer, new MoveOperation(observer, scheduler, metadata)); remove_operation_.reset( new RemoveOperation(observer, scheduler, metadata, cache)); + touch_operation_.reset( + new TouchOperation(blocking_task_runner, observer, scheduler, metadata)); update_operation_.reset( new UpdateOperation(observer, scheduler, metadata, cache)); search_operation_.reset( @@ -134,6 +137,19 @@ void DriveOperations::Remove(const base::FilePath& file_path, remove_operation_->Remove(file_path, is_recursive, callback); } +void DriveOperations::TouchFile(const base::FilePath& file_path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const FileOperationCallback& callback) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(!last_access_time.is_null()); + DCHECK(!last_modified_time.is_null()); + DCHECK(!callback.is_null()); + + touch_operation_->TouchFile( + file_path, last_access_time, last_modified_time, callback); +} + void DriveOperations::UpdateFileByResourceId( const std::string& resource_id, DriveClientContext context, diff --git a/chrome/browser/chromeos/drive/file_system/drive_operations.h b/chrome/browser/chromeos/drive/file_system/drive_operations.h index 84e5a99..82ef73a 100644 --- a/chrome/browser/chromeos/drive/file_system/drive_operations.h +++ b/chrome/browser/chromeos/drive/file_system/drive_operations.h @@ -11,6 +11,7 @@ namespace base { class FilePath; class SequencedTaskRunner; +class Time; } // namespace base namespace google_apis { @@ -35,6 +36,7 @@ class MoveOperation; class OperationObserver; class RemoveOperation; class SearchOperation; +class TouchOperation; class UpdateOperation; // Callback for DriveOperations::Search. @@ -111,6 +113,13 @@ class DriveOperations { bool is_recursive, const FileOperationCallback& callback); + // Wrapper function for touch_operation_. + // |callback| must not be null. + void TouchFile(const base::FilePath& file_path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const FileOperationCallback& callback); + // Wrapper function for update_operation_. // |callback| must not be null. void UpdateFileByResourceId(const std::string& resource_id, @@ -129,6 +138,7 @@ class DriveOperations { scoped_ptr<CreateFileOperation> create_file_operation_; scoped_ptr<MoveOperation> move_operation_; scoped_ptr<RemoveOperation> remove_operation_; + scoped_ptr<TouchOperation> touch_operation_; scoped_ptr<UpdateOperation> update_operation_; scoped_ptr<SearchOperation> search_operation_; }; diff --git a/chrome/browser/chromeos/drive/file_system/touch_operation.cc b/chrome/browser/chromeos/drive/file_system/touch_operation.cc new file mode 100644 index 0000000..3bda5ff --- /dev/null +++ b/chrome/browser/chromeos/drive/file_system/touch_operation.cc @@ -0,0 +1,122 @@ +// Copyright 2013 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/drive/file_system/touch_operation.h" + +#include "base/bind.h" +#include "base/files/file_path.h" +#include "base/sequenced_task_runner.h" +#include "base/time.h" +#include "chrome/browser/chromeos/drive/file_errors.h" +#include "chrome/browser/chromeos/drive/file_system/operation_observer.h" +#include "chrome/browser/chromeos/drive/file_system_util.h" +#include "chrome/browser/chromeos/drive/job_scheduler.h" +#include "chrome/browser/chromeos/drive/resource_entry_conversion.h" +#include "chrome/browser/chromeos/drive/resource_metadata.h" +#include "content/public/browser/browser_thread.h" + +using content::BrowserThread; + +namespace drive { +namespace file_system { + +TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner, + OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata) + : blocking_task_runner_(blocking_task_runner), + observer_(observer), + scheduler_(scheduler), + metadata_(metadata), + weak_ptr_factory_(this) { +} + +TouchOperation::~TouchOperation() { +} + +void TouchOperation::TouchFile(const base::FilePath& file_path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const FileOperationCallback& callback) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(!callback.is_null()); + + ResourceEntry* entry = new ResourceEntry; + base::PostTaskAndReplyWithResult( + blocking_task_runner_, + FROM_HERE, + base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, + base::Unretained(metadata_), file_path, entry), + base::Bind(&TouchOperation::TouchFileAfterGetResourceEntry, + weak_ptr_factory_.GetWeakPtr(), + file_path, last_access_time, last_modified_time, callback, + base::Owned(entry))); +} + +void TouchOperation::TouchFileAfterGetResourceEntry( + const base::FilePath& file_path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const FileOperationCallback& callback, + ResourceEntry* entry, + FileError error) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(!callback.is_null()); + DCHECK(entry); + + if (error != FILE_ERROR_OK) { + callback.Run(error); + return; + } + + // Note: |last_modified_time| is mapped to modifiedDate, |last_access_time| + // is mapped to lastViewedByMeDate. See also ConvertToResourceEntry(). + scheduler_->TouchResource( + entry->resource_id(), last_modified_time, last_access_time, + base::Bind(&TouchOperation::TouchFileAfterServerTimeStampUpdated, + weak_ptr_factory_.GetWeakPtr(), + file_path, callback)); +} + +void TouchOperation::TouchFileAfterServerTimeStampUpdated( + const base::FilePath& file_path, + const FileOperationCallback& callback, + google_apis::GDataErrorCode gdata_error, + scoped_ptr<google_apis::ResourceEntry> resource_entry) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(!callback.is_null()); + + FileError error = util::GDataToFileError(gdata_error); + if (error != FILE_ERROR_OK) { + callback.Run(error); + return; + } + + base::PostTaskAndReplyWithResult( + blocking_task_runner_, + FROM_HERE, + base::Bind(&internal::ResourceMetadata::RefreshEntry, + base::Unretained(metadata_), + ConvertToResourceEntry(*resource_entry), + static_cast<base::FilePath*>(NULL), + static_cast<ResourceEntry*>(NULL)), + base::Bind(&TouchOperation::TouchFileAfterRefreshMetadata, + weak_ptr_factory_.GetWeakPtr(), file_path, callback)); +} + +void TouchOperation::TouchFileAfterRefreshMetadata( + const base::FilePath& file_path, + const FileOperationCallback& callback, + FileError error) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(!callback.is_null()); + + if (error == FILE_ERROR_OK) + observer_->OnDirectoryChangedByOperation(file_path.DirName()); + + callback.Run(error); +} + +} // namespace file_system +} // namespace drive diff --git a/chrome/browser/chromeos/drive/file_system/touch_operation.h b/chrome/browser/chromeos/drive/file_system/touch_operation.h new file mode 100644 index 0000000..48a3590 --- /dev/null +++ b/chrome/browser/chromeos/drive/file_system/touch_operation.h @@ -0,0 +1,89 @@ +// Copyright 2013 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_DRIVE_FILE_SYSTEM_TOUCH_OPERATION_H_ +#define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TOUCH_OPERATION_H_ + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "chrome/browser/chromeos/drive/file_errors.h" +#include "chrome/browser/google_apis/gdata_errorcode.h" + +namespace base { +class FilePath; +class SequencedTaskRunner; +class Time; +} // namespace base + +namespace google_apis { +class ResourceEntry; +} // namespace google_apis + +namespace drive { +namespace internal { +class ResourceMetadata; +} // namespace internal + +class JobScheduler; +class ResourceEntry; + +namespace file_system { + +class OperationObserver; + +class TouchOperation { + public: + TouchOperation(base::SequencedTaskRunner* blocking_task_runner, + OperationObserver* observer, + JobScheduler* scheduler, + internal::ResourceMetadata* metadata); + ~TouchOperation(); + + // Touches the file by updating last access time and last modified time. + // Upon completion, invokes |callback|. + // |last_access_time|, |last_modified_time| and |callback| must not be null. + void TouchFile(const base::FilePath& file_path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const FileOperationCallback& callback); + + private: + // Part of TouchFile(). Runs after GetResourceEntry is completed. + void TouchFileAfterGetResourceEntry(const base::FilePath& file_path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const FileOperationCallback& callback, + ResourceEntry* entry, + FileError error); + + // Part of TouchFile(). Runs after the server side update for last access time + // and last modified time is completed. + void TouchFileAfterServerTimeStampUpdated( + const base::FilePath& file_path, + const FileOperationCallback& callback, + google_apis::GDataErrorCode gdata_error, + scoped_ptr<google_apis::ResourceEntry> resource_entry); + + // Part of TouchFile(). Runs after refreshing the local metadata is completed. + void TouchFileAfterRefreshMetadata(const base::FilePath& file_path, + const FileOperationCallback& callback, + FileError error); + + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; + OperationObserver* observer_; + JobScheduler* scheduler_; + internal::ResourceMetadata* metadata_; + + // Note: This should remain the last member so it'll be destroyed and + // invalidate the weak pointers before any other members are destroyed. + base::WeakPtrFactory<TouchOperation> weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(TouchOperation); +}; + +} // namespace file_system +} // namespace drive + +#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TOUCH_OPERATION_H_ diff --git a/chrome/browser/chromeos/drive/file_system/touch_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/touch_operation_unittest.cc new file mode 100644 index 0000000..4e0f71d --- /dev/null +++ b/chrome/browser/chromeos/drive/file_system/touch_operation_unittest.cc @@ -0,0 +1,59 @@ +// Copyright 2013 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/drive/file_system/touch_operation.h" + +#include "base/files/file_path.h" +#include "base/time.h" +#include "chrome/browser/chromeos/drive/drive.pb.h" +#include "chrome/browser/chromeos/drive/file_errors.h" +#include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" +#include "chrome/browser/chromeos/drive/resource_metadata.h" +#include "chrome/browser/google_apis/test_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace drive { +namespace file_system { + +typedef OperationTestBase TouchOperationTest; + +TEST_F(TouchOperationTest, TouchFile) { + TouchOperation operation(blocking_task_runner(), + dummy_observer(), + scheduler(), + metadata()); + + const base::FilePath kTestPath(FILE_PATH_LITERAL("drive/root/File 1.txt")); + const base::Time::Exploded kLastAccessTime = { + 2012, 7, 0, 19, 15, 59, 13, 123 + }; + const base::Time::Exploded kLastModifiedTime = { + 2013, 7, 0, 19, 15, 59, 13, 123 + }; + + FileError error = FILE_ERROR_FAILED; + operation.TouchFile( + kTestPath, + base::Time::FromUTCExploded(kLastAccessTime), + base::Time::FromUTCExploded(kLastModifiedTime), + google_apis::test_util::CreateCopyResultCallback(&error)); + google_apis::test_util::RunBlockingPoolTask(); + EXPECT_EQ(FILE_ERROR_OK, error); + + ResourceEntry entry; + base::PostTaskAndReplyWithResult( + blocking_task_runner(), FROM_HERE, + base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, + base::Unretained(metadata()), kTestPath, &entry), + base::Bind(google_apis::test_util::CreateCopyResultCallback(&error))); + google_apis::test_util::RunBlockingPoolTask(); + EXPECT_EQ(FILE_ERROR_OK, error); + EXPECT_EQ(base::Time::FromUTCExploded(kLastAccessTime), + base::Time::FromInternalValue(entry.file_info().last_accessed())); + EXPECT_EQ(base::Time::FromUTCExploded(kLastModifiedTime), + base::Time::FromInternalValue(entry.file_info().last_modified())); +} + +} // namespace file_system +} // namespace drive diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index c1f7ab5..a167304 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -252,6 +252,8 @@ 'browser/chromeos/drive/file_system/remove_operation.h', 'browser/chromeos/drive/file_system/search_operation.cc', 'browser/chromeos/drive/file_system/search_operation.h', + 'browser/chromeos/drive/file_system/touch_operation.cc', + 'browser/chromeos/drive/file_system/touch_operation.h', 'browser/chromeos/drive/file_system/update_operation.cc', 'browser/chromeos/drive/file_system/update_operation.h', 'browser/chromeos/drive/file_system_interface.h', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 1068c31..df215301 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -585,6 +585,7 @@ 'browser/chromeos/drive/file_system/create_file_operation_unittest.cc', 'browser/chromeos/drive/file_system/operation_test_base.cc', 'browser/chromeos/drive/file_system/operation_test_base.h', + 'browser/chromeos/drive/file_system/touch_operation_unittest.cc', 'browser/chromeos/drive/file_system_util_unittest.cc', 'browser/chromeos/drive/file_write_helper_unittest.cc', 'browser/chromeos/drive/job_queue_unittest.cc', |