- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / file_system / touch_operation.h
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 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TOUCH_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TOUCH_OPERATION_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/drive/file_errors.h"
13 #include "chrome/browser/google_apis/gdata_errorcode.h"
14
15 namespace base {
16 class FilePath;
17 class SequencedTaskRunner;
18 class Time;
19 }  // namespace base
20
21 namespace google_apis {
22 class ResourceEntry;
23 }  // namespace google_apis
24
25 namespace drive {
26 namespace internal {
27 class ResourceMetadata;
28 }  // namespace internal
29
30 class JobScheduler;
31 class ResourceEntry;
32
33 namespace file_system {
34
35 class OperationObserver;
36
37 class TouchOperation {
38  public:
39   TouchOperation(base::SequencedTaskRunner* blocking_task_runner,
40                  OperationObserver* observer,
41                  JobScheduler* scheduler,
42                  internal::ResourceMetadata* metadata);
43   ~TouchOperation();
44
45   // Touches the file by updating last access time and last modified time.
46   // Upon completion, invokes |callback|.
47   // |last_access_time|, |last_modified_time| and |callback| must not be null.
48   void TouchFile(const base::FilePath& file_path,
49                  const base::Time& last_access_time,
50                  const base::Time& last_modified_time,
51                  const FileOperationCallback& callback);
52
53  private:
54   // Part of TouchFile(). Runs after GetResourceEntry is completed.
55   void TouchFileAfterGetResourceEntry(const base::Time& last_access_time,
56                                       const base::Time& last_modified_time,
57                                       const FileOperationCallback& callback,
58                                       std::string* local_id,
59                                       ResourceEntry* entry,
60                                       FileError error);
61
62   // Part of TouchFile(). Runs after the server side update for last access time
63   // and last modified time is completed.
64   void TouchFileAfterServerTimeStampUpdated(
65       const std::string& local_id,
66       const FileOperationCallback& callback,
67       google_apis::GDataErrorCode gdata_error,
68       scoped_ptr<google_apis::ResourceEntry> resource_entry);
69
70   // Part of TouchFile(). Runs after refreshing the local metadata is completed.
71   void TouchFileAfterRefreshMetadata(const base::FilePath* file_path,
72                                      const FileOperationCallback& callback,
73                                      FileError error);
74
75   scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
76   OperationObserver* observer_;
77   JobScheduler* scheduler_;
78   internal::ResourceMetadata* metadata_;
79
80   // Note: This should remain the last member so it'll be destroyed and
81   // invalidate the weak pointers before any other members are destroyed.
82   base::WeakPtrFactory<TouchOperation> weak_ptr_factory_;
83   DISALLOW_COPY_AND_ASSIGN(TouchOperation);
84 };
85
86 }  // namespace file_system
87 }  // namespace drive
88
89 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TOUCH_OPERATION_H_