touch_operation.h revision 116680a4aac90f2aa7413d9095a592090648e557
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 "google_apis/drive/gdata_errorcode.h"
14
15namespace base {
16class FilePath;
17class SequencedTaskRunner;
18class Time;
19}  // namespace base
20
21namespace google_apis {
22class ResourceEntry;
23}  // namespace google_apis
24
25namespace drive {
26namespace internal {
27class ResourceMetadata;
28}  // namespace internal
29
30class ResourceEntry;
31
32namespace file_system {
33
34class OperationObserver;
35
36class TouchOperation {
37 public:
38  TouchOperation(base::SequencedTaskRunner* blocking_task_runner,
39                 OperationObserver* observer,
40                 internal::ResourceMetadata* metadata);
41  ~TouchOperation();
42
43  // Touches the file by updating last access time and last modified time.
44  // Upon completion, invokes |callback|.
45  // |last_access_time|, |last_modified_time| and |callback| must not be null.
46  void TouchFile(const base::FilePath& file_path,
47                 const base::Time& last_access_time,
48                 const base::Time& last_modified_time,
49                 const FileOperationCallback& callback);
50
51 private:
52  // Part of TouchFile(). Runs after updating the local state.
53  void TouchFileAfterUpdateLocalState(const base::FilePath& file_path,
54                                      const FileOperationCallback& callback,
55                                      const ResourceEntry* entry,
56                                      const std::string* local_id,
57                                      FileError error);
58
59  scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
60  OperationObserver* observer_;
61  internal::ResourceMetadata* metadata_;
62
63  // Note: This should remain the last member so it'll be destroyed and
64  // invalidate the weak pointers before any other members are destroyed.
65  base::WeakPtrFactory<TouchOperation> weak_ptr_factory_;
66  DISALLOW_COPY_AND_ASSIGN(TouchOperation);
67};
68
69}  // namespace file_system
70}  // namespace drive
71
72#endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_TOUCH_OPERATION_H_
73