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

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

Issue 343073003: Files.app: Provide detailed change information on onDirectoryChanged event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed the comments Created 6 years, 6 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 2013 The Chromium Authors. All rights reserved. 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 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/drive/file_system/touch_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/touch_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/sequenced_task_runner.h" 9 #include "base/sequenced_task_runner.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "chrome/browser/chromeos/drive/file_change.h"
11 #include "chrome/browser/chromeos/drive/file_errors.h" 12 #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/operation_observer.h"
13 #include "chrome/browser/chromeos/drive/resource_metadata.h" 14 #include "chrome/browser/chromeos/drive/resource_metadata.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 16
16 using content::BrowserThread; 17 using content::BrowserThread;
17 18
18 namespace drive { 19 namespace drive {
19 namespace file_system { 20 namespace file_system {
20 21
21 namespace { 22 namespace {
22 23
23 // Updates the timestamps of the entry specified by |file_path|. 24 // Updates the timestamps of the entry specified by |file_path|.
24 FileError UpdateLocalState(internal::ResourceMetadata* metadata, 25 FileError UpdateLocalState(internal::ResourceMetadata* metadata,
25 const base::FilePath& file_path, 26 const base::FilePath& file_path,
26 const base::Time& last_access_time, 27 const base::Time& last_access_time,
27 const base::Time& last_modified_time, 28 const base::Time& last_modified_time,
28 std::string* local_id) { 29 ResourceEntry* entry,
29 ResourceEntry entry; 30 std::string* local_id) {
30 FileError error = metadata->GetResourceEntryByPath(file_path, &entry); 31
32 FileError error = metadata->GetResourceEntryByPath(file_path, entry);
31 if (error != FILE_ERROR_OK) 33 if (error != FILE_ERROR_OK)
32 return error; 34 return error;
33 *local_id = entry.local_id(); 35 *local_id = entry->local_id();
34 36
35 PlatformFileInfoProto* file_info = entry.mutable_file_info(); 37 PlatformFileInfoProto* file_info = entry->mutable_file_info();
36 if (!last_access_time.is_null()) 38 if (!last_access_time.is_null())
37 file_info->set_last_accessed(last_access_time.ToInternalValue()); 39 file_info->set_last_accessed(last_access_time.ToInternalValue());
38 if (!last_modified_time.is_null()) 40 if (!last_modified_time.is_null())
39 file_info->set_last_modified(last_modified_time.ToInternalValue()); 41 file_info->set_last_modified(last_modified_time.ToInternalValue());
40 entry.set_metadata_edit_state(ResourceEntry::DIRTY); 42 entry->set_metadata_edit_state(ResourceEntry::DIRTY);
41 entry.set_modification_date(base::Time::Now().ToInternalValue()); 43 entry->set_modification_date(base::Time::Now().ToInternalValue());
42 return metadata->RefreshEntry(entry); 44 return metadata->RefreshEntry(*entry);
43 } 45 }
44 46
45 } // namespace 47 } // namespace
46 48
47 TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner, 49 TouchOperation::TouchOperation(base::SequencedTaskRunner* blocking_task_runner,
48 OperationObserver* observer, 50 OperationObserver* observer,
49 internal::ResourceMetadata* metadata) 51 internal::ResourceMetadata* metadata)
50 : blocking_task_runner_(blocking_task_runner), 52 : blocking_task_runner_(blocking_task_runner),
51 observer_(observer), 53 observer_(observer),
52 metadata_(metadata), 54 metadata_(metadata),
53 weak_ptr_factory_(this) { 55 weak_ptr_factory_(this) {
54 } 56 }
55 57
56 TouchOperation::~TouchOperation() { 58 TouchOperation::~TouchOperation() {
57 } 59 }
58 60
59 void TouchOperation::TouchFile(const base::FilePath& file_path, 61 void TouchOperation::TouchFile(const base::FilePath& file_path,
60 const base::Time& last_access_time, 62 const base::Time& last_access_time,
61 const base::Time& last_modified_time, 63 const base::Time& last_modified_time,
62 const FileOperationCallback& callback) { 64 const FileOperationCallback& callback) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
64 DCHECK(!callback.is_null()); 66 DCHECK(!callback.is_null());
65 67
66 std::string* local_id = new std::string; 68 std::string* local_id = new std::string;
69 ResourceEntry* entry = new ResourceEntry;
67 base::PostTaskAndReplyWithResult( 70 base::PostTaskAndReplyWithResult(
68 blocking_task_runner_.get(), 71 blocking_task_runner_.get(),
69 FROM_HERE, 72 FROM_HERE,
70 base::Bind(&UpdateLocalState, 73 base::Bind(&UpdateLocalState,
71 metadata_, 74 metadata_,
72 file_path, 75 file_path,
73 last_access_time, 76 last_access_time,
74 last_modified_time, 77 last_modified_time,
78 entry,
75 local_id), 79 local_id),
76 base::Bind(&TouchOperation::TouchFileAfterUpdateLocalState, 80 base::Bind(&TouchOperation::TouchFileAfterUpdateLocalState,
77 weak_ptr_factory_.GetWeakPtr(), 81 weak_ptr_factory_.GetWeakPtr(),
78 file_path, 82 file_path,
79 callback, 83 callback,
84 base::Owned(entry),
80 base::Owned(local_id))); 85 base::Owned(local_id)));
81 } 86 }
82 87
83 void TouchOperation::TouchFileAfterUpdateLocalState( 88 void TouchOperation::TouchFileAfterUpdateLocalState(
84 const base::FilePath& file_path, 89 const base::FilePath& file_path,
85 const FileOperationCallback& callback, 90 const FileOperationCallback& callback,
91 const ResourceEntry* entry,
86 const std::string* local_id, 92 const std::string* local_id,
87 FileError error) { 93 FileError error) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
89 DCHECK(!callback.is_null()); 95 DCHECK(!callback.is_null());
96 DCHECK(!entry->file_info().is_directory());
97
98 FileChange changed_files;
99 changed_files.Update(
100 file_path, FileChange::FILE_TYPE_FILE, FileChange::ADD_OR_UPDATE);
90 101
91 if (error == FILE_ERROR_OK) { 102 if (error == FILE_ERROR_OK) {
92 observer_->OnDirectoryChangedByOperation(file_path.DirName()); 103 observer_->OnFileChangedByOperation(changed_files);
93 observer_->OnEntryUpdatedByOperation(*local_id); 104 observer_->OnEntryUpdatedByOperation(*local_id);
94 } 105 }
95 callback.Run(error); 106 callback.Run(error);
96 } 107 }
97 108
98 } // namespace file_system 109 } // namespace file_system
99 } // namespace drive 110 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698