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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10825459: gdata: Move task related functions like RunTaskOnUIThread from gdata_file_system.cc to task_util.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/task_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/json/json_file_value_serializer.h" 12 #include "base/json/json_file_value_serializer.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/message_loop_proxy.h" 14 #include "base/message_loop_proxy.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/platform_file.h" 16 #include "base/platform_file.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" 19 #include "chrome/browser/chromeos/gdata/drive_api_parser.h"
20 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" 20 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
21 #include "chrome/browser/chromeos/gdata/gdata.pb.h" 21 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
22 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" 22 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
23 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" 23 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
24 #include "chrome/browser/chromeos/gdata/gdata_files.h" 24 #include "chrome/browser/chromeos/gdata/gdata_files.h"
25 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" 25 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h"
26 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 26 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
27 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" 27 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
28 #include "chrome/browser/chromeos/gdata/gdata_util.h" 28 #include "chrome/browser/chromeos/gdata/gdata_util.h"
29 #include "chrome/browser/chromeos/gdata/task_util.h"
29 #include "chrome/browser/prefs/pref_service.h" 30 #include "chrome/browser/prefs/pref_service.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/common/chrome_notification_types.h" 32 #include "chrome/common/chrome_notification_types.h"
32 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
33 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/notification_details.h" 35 #include "content/public/browser/notification_details.h"
35 #include "net/base/mime_util.h" 36 #include "net/base/mime_util.h"
36 37
37 using content::BrowserThread; 38 using content::BrowserThread;
38 39
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 void CopyLocalFileOnBlockingPool( 231 void CopyLocalFileOnBlockingPool(
231 const FilePath& src_file_path, 232 const FilePath& src_file_path,
232 const FilePath& dest_file_path, 233 const FilePath& dest_file_path,
233 GDataFileError* error) { 234 GDataFileError* error) {
234 DCHECK(error); 235 DCHECK(error);
235 236
236 *error = file_util::CopyFile(src_file_path, dest_file_path) ? 237 *error = file_util::CopyFile(src_file_path, dest_file_path) ?
237 GDATA_FILE_OK : GDATA_FILE_ERROR_FAILED; 238 GDATA_FILE_OK : GDATA_FILE_ERROR_FAILED;
238 } 239 }
239 240
240 // Runs task on the thread to which |relay_proxy| belongs.
241 void RunTaskOnThread(scoped_refptr<base::MessageLoopProxy> relay_proxy,
242 const base::Closure& task) {
243 if (relay_proxy->BelongsToCurrentThread()) {
244 task.Run();
245 } else {
246 const bool posted = relay_proxy->PostTask(FROM_HERE, task);
247 DCHECK(posted);
248 }
249 }
250
251 // Callback for GetEntryByResourceIdAsync. 241 // Callback for GetEntryByResourceIdAsync.
252 // Adds |entry| to |results|. Runs |callback| with |results| when 242 // Adds |entry| to |results|. Runs |callback| with |results| when
253 // |run_callback| is true. When |entry| is not present in our local file system 243 // |run_callback| is true. When |entry| is not present in our local file system
254 // snapshot, it is not added to |results|. Instead, |entry_skipped_callback| is 244 // snapshot, it is not added to |results|. Instead, |entry_skipped_callback| is
255 // called. 245 // called.
256 void AddEntryToSearchResults( 246 void AddEntryToSearchResults(
257 std::vector<SearchResultInfo>* results, 247 std::vector<SearchResultInfo>* results,
258 const SearchCallback& callback, 248 const SearchCallback& callback,
259 const base::Closure& entry_skipped_callback, 249 const base::Closure& entry_skipped_callback,
260 GDataFileError error, 250 GDataFileError error,
(...skipping 12 matching lines...) Expand all
273 entry_skipped_callback.Run(); 263 entry_skipped_callback.Run();
274 } 264 }
275 265
276 if (run_callback) { 266 if (run_callback) {
277 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); 267 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results);
278 if (!callback.is_null()) 268 if (!callback.is_null())
279 callback.Run(error, next_feed, result_vec.Pass()); 269 callback.Run(error, next_feed, result_vec.Pass());
280 } 270 }
281 } 271 }
282 272
283 // Runs task on UI thread.
284 void RunTaskOnUIThread(const base::Closure& task) {
285 RunTaskOnThread(
286 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), task);
287 }
288
289 // RelayCallback relays arguments for callback running on the given thread.
290 template<typename CallbackType>
291 struct RelayCallback;
292
293 // RelayCallback for callback with one argument.
294 template<typename T1>
295 struct RelayCallback<base::Callback<void(T1)> > {
296 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
297 const base::Callback<void(T1)>& callback,
298 T1 arg1) {
299 if (callback.is_null())
300 return;
301 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1));
302 }
303 };
304
305 // RelayCallback for callback with two arguments.
306 template<typename T1, typename T2>
307 struct RelayCallback<base::Callback<void(T1, T2)> > {
308 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
309 const base::Callback<void(T1, T2)>& callback,
310 T1 arg1,
311 T2 arg2) {
312 if (callback.is_null())
313 return;
314 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1, arg2));
315 }
316 };
317
318 // RelayCallback for callback with two arguments, the last one is scoped_ptr.
319 template<typename T1, typename T2>
320 struct RelayCallback<base::Callback<void(T1, scoped_ptr<T2>)> > {
321 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
322 const base::Callback<void(T1, scoped_ptr<T2>)>& callback,
323 T1 arg1,
324 scoped_ptr<T2> arg2) {
325 if (callback.is_null())
326 return;
327 RunTaskOnThread(relay_proxy,
328 base::Bind(callback, arg1, base::Passed(&arg2)));
329 }
330 };
331
332 // RelayCallback for callback with three arguments.
333 template<typename T1, typename T2, typename T3>
334 struct RelayCallback<base::Callback<void(T1, T2, T3)> > {
335 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
336 const base::Callback<void(T1, T2, T3)>& callback,
337 T1 arg1,
338 T2 arg2,
339 T3 arg3) {
340 if (callback.is_null())
341 return;
342 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1, arg2, arg3));
343 }
344 };
345
346 // RelayCallback for callback with three arguments, the last one is scoped_ptr.
347 template<typename T1, typename T2, typename T3>
348 struct RelayCallback<base::Callback<void(T1, T2, scoped_ptr<T3>)> > {
349 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
350 const base::Callback<void(T1, T2, scoped_ptr<T3>)>& callback,
351 T1 arg1,
352 T2 arg2,
353 scoped_ptr<T3> arg3) {
354 if (callback.is_null())
355 return;
356 RunTaskOnThread(relay_proxy,
357 base::Bind(callback, arg1, arg2, base::Passed(&arg3)));
358 }
359 };
360
361 // RelayCallback for callback with four arguments.
362 template<typename T1, typename T2, typename T3, typename T4>
363 struct RelayCallback<base::Callback<void(T1, T2, T3, T4)> > {
364 static void Run(scoped_refptr<base::MessageLoopProxy> relay_proxy,
365 const base::Callback<void(T1, T2, T3, T4)>& callback,
366 T1 arg1,
367 T2 arg2,
368 T3 arg3,
369 T4 arg4) {
370 if (callback.is_null())
371 return;
372 RunTaskOnThread(relay_proxy, base::Bind(callback, arg1, arg2, arg3, arg4));
373 }
374 };
375
376 // Returns callback which runs the given |callback| on the current thread.
377 template<typename CallbackType>
378 CallbackType CreateRelayCallback(const CallbackType& callback) {
379 return base::Bind(&RelayCallback<CallbackType>::Run,
380 base::MessageLoopProxy::current(),
381 callback);
382 }
383
384 // Helper function for binding |path| to GetEntryInfoWithFilePathCallback and 273 // Helper function for binding |path| to GetEntryInfoWithFilePathCallback and
385 // create GetEntryInfoCallback. 274 // create GetEntryInfoCallback.
386 void RunGetEntryInfoWithFilePathCallback( 275 void RunGetEntryInfoWithFilePathCallback(
387 const GetEntryInfoWithFilePathCallback& callback, 276 const GetEntryInfoWithFilePathCallback& callback,
388 const FilePath& path, 277 const FilePath& path,
389 GDataFileError error, 278 GDataFileError error,
390 scoped_ptr<GDataEntryProto> entry_proto) { 279 scoped_ptr<GDataEntryProto> entry_proto) {
391 if (!callback.is_null()) 280 if (!callback.is_null())
392 callback.Run(error, path, entry_proto.Pass()); 281 callback.Run(error, path, entry_proto.Pass());
393 } 282 }
(...skipping 3048 matching lines...) Expand 10 before | Expand all | Expand 10 after
3442 return; 3331 return;
3443 } 3332 }
3444 3333
3445 PlatformFileInfoProto entry_file_info; 3334 PlatformFileInfoProto entry_file_info;
3446 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3335 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3447 *entry_proto->mutable_file_info() = entry_file_info; 3336 *entry_proto->mutable_file_info() = entry_file_info;
3448 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3337 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3449 } 3338 }
3450 3339
3451 } // namespace gdata 3340 } // namespace gdata
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/task_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698