1 // Copyright 2014 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 #include "chrome/browser/chromeos/file_system_provider/operations/remove_watcher.h"
6 
7 #include <string>
8 
9 #include "chrome/common/extensions/api/file_system_provider.h"
10 #include "chrome/common/extensions/api/file_system_provider_internal.h"
11 
12 namespace chromeos {
13 namespace file_system_provider {
14 namespace operations {
15 
RemoveWatcher(extensions::EventRouter * event_router,const ProvidedFileSystemInfo & file_system_info,const base::FilePath & entry_path,bool recursive,storage::AsyncFileUtil::StatusCallback callback)16 RemoveWatcher::RemoveWatcher(extensions::EventRouter* event_router,
17                              const ProvidedFileSystemInfo& file_system_info,
18                              const base::FilePath& entry_path,
19                              bool recursive,
20                              storage::AsyncFileUtil::StatusCallback callback)
21     : Operation(event_router, file_system_info),
22       entry_path_(entry_path),
23       recursive_(recursive),
24       callback_(std::move(callback)) {}
25 
~RemoveWatcher()26 RemoveWatcher::~RemoveWatcher() {
27 }
28 
Execute(int request_id)29 bool RemoveWatcher::Execute(int request_id) {
30   using extensions::api::file_system_provider::RemoveWatcherRequestedOptions;
31 
32   RemoveWatcherRequestedOptions options;
33   options.file_system_id = file_system_info_.file_system_id();
34   options.request_id = request_id;
35   options.entry_path = entry_path_.AsUTF8Unsafe();
36   options.recursive = recursive_;
37 
38   return SendEvent(
39       request_id,
40       extensions::events::FILE_SYSTEM_PROVIDER_ON_REMOVE_WATCHER_REQUESTED,
41       extensions::api::file_system_provider::OnRemoveWatcherRequested::
42           kEventName,
43       extensions::api::file_system_provider::OnRemoveWatcherRequested::Create(
44           options));
45 }
46 
OnSuccess(int,std::unique_ptr<RequestValue>,bool has_more)47 void RemoveWatcher::OnSuccess(int /* request_id */,
48                               std::unique_ptr<RequestValue> /* result */,
49                               bool has_more) {
50   DCHECK(callback_);
51   std::move(callback_).Run(base::File::FILE_OK);
52 }
53 
OnError(int,std::unique_ptr<RequestValue>,base::File::Error error)54 void RemoveWatcher::OnError(int /* request_id */,
55                             std::unique_ptr<RequestValue> /* result */,
56                             base::File::Error error) {
57   DCHECK(callback_);
58   std::move(callback_).Run(error);
59 }
60 
61 }  // namespace operations
62 }  // namespace file_system_provider
63 }  // namespace chromeos
64