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

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

Issue 23816002: drive: Stop using resource ID to access local metadata in OpenFileOperation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new Created 7 years, 2 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/open_file_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 if (error != FILE_ERROR_OK) { 119 if (error != FILE_ERROR_OK) {
120 callback.Run(error, base::FilePath(), base::Closure()); 120 callback.Run(error, base::FilePath(), base::Closure());
121 return; 121 return;
122 } 122 }
123 123
124 base::PostTaskAndReplyWithResult( 124 base::PostTaskAndReplyWithResult(
125 blocking_task_runner_.get(), 125 blocking_task_runner_.get(),
126 FROM_HERE, 126 FROM_HERE,
127 base::Bind(&internal::FileCache::MarkDirty, 127 base::Bind(&internal::FileCache::MarkDirty,
128 base::Unretained(cache_), 128 base::Unretained(cache_),
129 entry->resource_id()), 129 entry->local_id()),
130 base::Bind(&OpenFileOperation::OpenFileAfterMarkDirty, 130 base::Bind(&OpenFileOperation::OpenFileAfterMarkDirty,
131 weak_ptr_factory_.GetWeakPtr(), 131 weak_ptr_factory_.GetWeakPtr(),
132 local_file_path, 132 local_file_path,
133 entry->resource_id(), 133 entry->local_id(),
134 callback)); 134 callback));
135 } 135 }
136 136
137 void OpenFileOperation::OpenFileAfterMarkDirty( 137 void OpenFileOperation::OpenFileAfterMarkDirty(
138 const base::FilePath& local_file_path, 138 const base::FilePath& local_file_path,
139 const std::string& resource_id, 139 const std::string& local_id,
140 const OpenFileCallback& callback, 140 const OpenFileCallback& callback,
141 FileError error) { 141 FileError error) {
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
143 DCHECK(!callback.is_null()); 143 DCHECK(!callback.is_null());
144 144
145 if (error != FILE_ERROR_OK) { 145 if (error != FILE_ERROR_OK) {
146 callback.Run(error, base::FilePath(), base::Closure()); 146 callback.Run(error, base::FilePath(), base::Closure());
147 return; 147 return;
148 } 148 }
149 149
150 ++open_files_[resource_id]; 150 ++open_files_[local_id];
151 callback.Run(error, local_file_path, 151 callback.Run(error, local_file_path,
152 base::Bind(&OpenFileOperation::CloseFile, 152 base::Bind(&OpenFileOperation::CloseFile,
153 weak_ptr_factory_.GetWeakPtr(), resource_id)); 153 weak_ptr_factory_.GetWeakPtr(), local_id));
154 } 154 }
155 155
156 void OpenFileOperation::CloseFile(const std::string& resource_id) { 156 void OpenFileOperation::CloseFile(const std::string& local_id) {
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
158 DCHECK_GT(open_files_[resource_id], 0); 158 DCHECK_GT(open_files_[local_id], 0);
159 159
160 if (--open_files_[resource_id] == 0) { 160 if (--open_files_[local_id] == 0) {
161 // All clients closes this file, so notify to upload the file. 161 // All clients closes this file, so notify to upload the file.
162 open_files_.erase(resource_id); 162 open_files_.erase(local_id);
163 observer_->OnCacheFileUploadNeededByOperation(resource_id); 163 observer_->OnCacheFileUploadNeededByOperation(local_id);
164 164
165 // Clients may have enlarged the file. By FreeDiskpSpaceIfNeededFor(0), 165 // Clients may have enlarged the file. By FreeDiskpSpaceIfNeededFor(0),
166 // we try to ensure (0 + the-minimum-safe-margin = 512MB as of now) space. 166 // we try to ensure (0 + the-minimum-safe-margin = 512MB as of now) space.
167 blocking_task_runner_->PostTask( 167 blocking_task_runner_->PostTask(
168 FROM_HERE, 168 FROM_HERE,
169 base::Bind(base::IgnoreResult( 169 base::Bind(base::IgnoreResult(
170 base::Bind(&internal::FileCache::FreeDiskSpaceIfNeededFor, 170 base::Bind(&internal::FileCache::FreeDiskSpaceIfNeededFor,
171 base::Unretained(cache_), 171 base::Unretained(cache_),
172 0)))); 172 0))));
173 } 173 }
174 } 174 }
175 175
176 } // namespace file_system 176 } // namespace file_system
177 } // namespace drive 177 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698