Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / chromeos / file_system_provider / operations / operation.h
blob491f653024dd464dbd71ffc912102d6ddb406f89
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_OPERATION_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_OPERATION_H_
8 #include <string>
10 #include "base/files/file.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
13 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
14 #include "extensions/browser/extension_event_histogram_value.h"
15 #include "storage/browser/fileapi/async_file_util.h"
17 namespace base {
18 class ListValue;
21 namespace extensions {
22 struct Event;
23 class EventRouter;
26 namespace chromeos {
27 namespace file_system_provider {
28 namespace operations {
30 // Base class for operation bridges between fileapi and providing extensions.
31 class Operation : public RequestManager::HandlerInterface {
32 public:
33 typedef base::Callback<bool(scoped_ptr<extensions::Event> event)>
34 DispatchEventImplCallback;
36 Operation(extensions::EventRouter* event_router,
37 const ProvidedFileSystemInfo& file_system_info);
38 ~Operation() override;
40 // RequestManager::HandlerInterface overrides.
41 bool Execute(int request_id) override = 0;
42 void OnSuccess(int request_id,
43 scoped_ptr<RequestValue> result,
44 bool has_more) override = 0;
45 void OnError(int request_id,
46 scoped_ptr<RequestValue> result,
47 base::File::Error error) override = 0;
49 // Sets custom dispatchign event implementation for tests.
50 void SetDispatchEventImplForTesting(
51 const DispatchEventImplCallback& callback);
53 protected:
54 // Sends an event to the providing extension. Returns false, if the providing
55 // extension does not handle the |event_name| event.
56 bool SendEvent(int request_id,
57 extensions::events::HistogramValue histogram_value,
58 const std::string& event_name,
59 scoped_ptr<base::ListValue> event_args);
61 ProvidedFileSystemInfo file_system_info_;
63 private:
64 DispatchEventImplCallback dispatch_event_impl_;
65 DISALLOW_COPY_AND_ASSIGN(Operation);
68 } // namespace operations
69 } // namespace file_system_provider
70 } // namespace chromeos
72 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_OPERATION_H_