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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/touch_operation.cc

Issue 15728006: Implement TouchFile on drive::FileSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/drive/file_system/touch_operation.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/sequenced_task_runner.h"
10 #include "base/time.h"
11 #include "chrome/browser/chromeos/drive/file_errors.h"
12 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
13 #include "chrome/browser/chromeos/drive/file_system_util.h"
14 #include "chrome/browser/chromeos/drive/job_scheduler.h"
15 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h"
16 #include "chrome/browser/chromeos/drive/resource_metadata.h"
17 #include "content/public/browser/browser_thread.h"
18
19 using content::BrowserThread;
20
21 namespace drive {
22 namespace file_system {
23
24 TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner,
25 OperationObserver* observer,
26 JobScheduler* scheduler,
27 internal::ResourceMetadata* metadata)
28 : blocking_task_runner_(blocking_task_runner),
29 observer_(observer),
30 scheduler_(scheduler),
31 metadata_(metadata),
32 weak_ptr_factory_(this) {
33 }
34
35 TouchOperation::~TouchOperation() {
36 }
37
38 void TouchOperation::TouchFile(const base::FilePath& file_path,
39 const base::Time& last_access_time,
40 const base::Time& last_modified_time,
41 const FileOperationCallback& callback) {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
43 DCHECK(!callback.is_null());
44
45 ResourceEntry* entry = new ResourceEntry;
46 base::PostTaskAndReplyWithResult(
47 blocking_task_runner_,
48 FROM_HERE,
49 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
50 base::Unretained(metadata_), file_path, entry),
51 base::Bind(&TouchOperation::TouchFileAfterGetResourceEntry,
52 weak_ptr_factory_.GetWeakPtr(),
53 file_path, last_access_time, last_modified_time, callback,
54 base::Owned(entry)));
55 }
56
57 void TouchOperation::TouchFileAfterGetResourceEntry(
58 const base::FilePath& file_path,
59 const base::Time& last_access_time,
60 const base::Time& last_modified_time,
61 const FileOperationCallback& callback,
62 ResourceEntry* entry,
63 FileError error) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 DCHECK(!callback.is_null());
66 DCHECK(entry);
67
68 if (error != FILE_ERROR_OK) {
69 callback.Run(error);
70 return;
71 }
72
73 // Note: |last_modified_time| is mapped to modifiedDate, |last_access_time|
74 // is mapped to lastViewedByMeDate. See also ConvertToResourceEntry().
75 scheduler_->TouchResource(
76 entry->resource_id(), last_modified_time, last_access_time,
77 base::Bind(&TouchOperation::TouchFileAfterServerTimeStampUpdated,
78 weak_ptr_factory_.GetWeakPtr(),
79 file_path, callback));
80 }
81
82 void TouchOperation::TouchFileAfterServerTimeStampUpdated(
83 const base::FilePath& file_path,
84 const FileOperationCallback& callback,
85 google_apis::GDataErrorCode gdata_error,
86 scoped_ptr<google_apis::ResourceEntry> resource_entry) {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 DCHECK(!callback.is_null());
89
90 FileError error = util::GDataToFileError(gdata_error);
91 if (error != FILE_ERROR_OK) {
92 callback.Run(error);
93 return;
94 }
95
96 base::PostTaskAndReplyWithResult(
97 blocking_task_runner_,
98 FROM_HERE,
99 base::Bind(&internal::ResourceMetadata::RefreshEntry,
100 base::Unretained(metadata_),
101 ConvertToResourceEntry(*resource_entry),
102 static_cast<base::FilePath*>(NULL),
103 static_cast<ResourceEntry*>(NULL)),
104 base::Bind(&TouchOperation::TouchFileAfterRefreshMetadata,
105 weak_ptr_factory_.GetWeakPtr(), file_path, callback));
106 }
107
108 void TouchOperation::TouchFileAfterRefreshMetadata(
109 const base::FilePath& file_path,
110 const FileOperationCallback& callback,
111 FileError error) {
112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
113 DCHECK(!callback.is_null());
114
115 if (error == FILE_ERROR_OK)
116 observer_->OnDirectoryChangedByOperation(file_path.DirName());
117
118 callback.Run(error);
119 }
120
121 } // namespace file_system
122 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698