summaryrefslogtreecommitdiffstats
path: root/components/drive/file_system/set_property_operation.h
blob: 2e04441799a2d4a991c9e0736081b6b9da97de53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_DRIVE_FILE_SYSTEM_SET_PROPERTY_OPERATION_H_
#define COMPONENTS_DRIVE_FILE_SYSTEM_SET_PROPERTY_OPERATION_H_

#include <string>

#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "components/drive/file_errors.h"
#include "google_apis/drive/drive_api_requests.h"

namespace base {
class FilePath;
class SequencedTaskRunner;
}  // namespace base

namespace drive {
namespace internal {
class ResourceMetadata;
}  // namespace internal

class ResourceEntry;

namespace file_system {

class OperationDelegate;

class SetPropertyOperation {
 public:
  SetPropertyOperation(base::SequencedTaskRunner* blocking_task_runner,
                       OperationDelegate* delegate,
                       internal::ResourceMetadata* metadata);
  ~SetPropertyOperation();

  // Sets the |key| property on the entry at |drive_file_path| with the
  // specified |visibility|. If the property already exists, it will be
  // overwritten.
  void SetProperty(const base::FilePath& drive_file_path,
                   google_apis::drive::Property::Visibility visibility,
                   const std::string& key,
                   const std::string& value,
                   const FileOperationCallback& callback);

 private:
  // Part of SetProperty(). Runs after updating the local state.
  void SetPropertyAfterUpdateLocalState(const FileOperationCallback& callback,
                                        const ResourceEntry* entry,
                                        FileError result);

  scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
  OperationDelegate* delegate_;
  internal::ResourceMetadata* metadata_;

  base::ThreadChecker thread_checker_;

  // Note: This should remain the last member so it'll be destroyed and
  // invalidate the weak pointers before any other members are destroyed.
  base::WeakPtrFactory<SetPropertyOperation> weak_ptr_factory_;
  DISALLOW_COPY_AND_ASSIGN(SetPropertyOperation);
};

}  // namespace file_system
}  // namespace drive

#endif  // COMPONENTS_DRIVE_FILE_SYSTEM_SET_PROPERTY_OPERATION_H_