OLD | NEW |
(Empty) | |
| 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 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_ |
| 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_ |
| 7 |
| 8 #include "chrome/browser/local_discovery/privet_device_resolver.h" |
| 9 #include "chrome/browser/local_discovery/privet_http.h" |
| 10 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" |
| 11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
| 12 #include "chrome/browser/local_discovery/storage/path_util.h" |
| 13 #include "content/public/browser/browser_context.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "net/url_request/url_request_context.h" |
| 16 #include "webkit/browser/fileapi/async_file_util.h" |
| 17 |
| 18 namespace local_discovery { |
| 19 |
| 20 class PrivetFileSystemAsyncOperation { |
| 21 public: |
| 22 virtual ~PrivetFileSystemAsyncOperation() {} |
| 23 |
| 24 virtual void Start() = 0; |
| 25 }; |
| 26 |
| 27 class PrivetFileSystemAsyncOperationContainer { |
| 28 public: |
| 29 virtual ~PrivetFileSystemAsyncOperationContainer() {} |
| 30 |
| 31 virtual void RemoveOperation( |
| 32 PrivetFileSystemAsyncOperation* operation) = 0; |
| 33 virtual void RemoveAllOperations() = 0; |
| 34 }; |
| 35 |
| 36 class PrivetFileSystemAsyncOperationUtil { |
| 37 public: |
| 38 class Delegate { |
| 39 public: |
| 40 Delegate() {} |
| 41 virtual ~Delegate() {} |
| 42 |
| 43 // |http_client| is the client for the resolved service, or NULL if |
| 44 // resolution failed. |path| is the canonical path within the privet |
| 45 // service. |
| 46 virtual void PrivetFileSystemResolved( |
| 47 PrivetHTTPClient* http_client, |
| 48 const std::string& path) = 0; |
| 49 }; |
| 50 |
| 51 // full_path |
| 52 PrivetFileSystemAsyncOperationUtil( |
| 53 const base::FilePath& full_path, |
| 54 net::URLRequestContextGetter* request_context, |
| 55 Delegate* delegate); |
| 56 ~PrivetFileSystemAsyncOperationUtil(); |
| 57 |
| 58 void Start(); |
| 59 |
| 60 private: |
| 61 void OnGotDeviceDescription(bool success, |
| 62 const DeviceDescription& device_description); |
| 63 void OnGotPrivetHTTP(scoped_ptr<PrivetHTTPClient> privet_http_client); |
| 64 |
| 65 ParsedPrivetPath parsed_path_; |
| 66 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 67 Delegate* delegate_; |
| 68 |
| 69 scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_; |
| 70 scoped_ptr<PrivetDeviceResolver> privet_device_resolver_; |
| 71 scoped_ptr<PrivetHTTPAsynchronousFactory> privet_async_factory_; |
| 72 scoped_ptr<PrivetHTTPResolution> privet_http_resolution_; |
| 73 scoped_ptr<PrivetHTTPClient> privet_client_; |
| 74 }; |
| 75 |
| 76 class PrivetFileSystemListOperation |
| 77 : public PrivetFileSystemAsyncOperationUtil::Delegate, |
| 78 public local_discovery::PrivetFileSystemAsyncOperation { |
| 79 public: |
| 80 PrivetFileSystemListOperation( |
| 81 const base::FilePath& full_path, |
| 82 content::BrowserContext* browser_context, |
| 83 PrivetFileSystemAsyncOperationContainer* async_file_util, |
| 84 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback); |
| 85 virtual ~PrivetFileSystemListOperation(); |
| 86 |
| 87 virtual void Start() OVERRIDE; |
| 88 |
| 89 virtual void PrivetFileSystemResolved( |
| 90 PrivetHTTPClient* http_client, |
| 91 const std::string& path) OVERRIDE; |
| 92 |
| 93 private: |
| 94 void StartOnUIThread(); |
| 95 void OnStorageListResult(const base::DictionaryValue* value); |
| 96 void TriggerCallback(base::File::Error result, |
| 97 const fileapi::AsyncFileUtil::EntryList& file_list, |
| 98 bool has_more); |
| 99 |
| 100 void TriggerCallbackOnIOThread( |
| 101 base::File::Error result, |
| 102 fileapi::AsyncFileUtil::EntryList file_list, |
| 103 bool has_more); |
| 104 |
| 105 base::FilePath full_path_; |
| 106 content::BrowserContext* browser_context_; |
| 107 scoped_ptr<PrivetFileSystemAsyncOperationUtil> core_; |
| 108 PrivetFileSystemAsyncOperationContainer* async_file_util_; |
| 109 fileapi::AsyncFileUtil::ReadDirectoryCallback callback_; |
| 110 |
| 111 scoped_ptr<PrivetJSONOperation> list_operation_; |
| 112 base::WeakPtrFactory<PrivetFileSystemListOperation> weak_factory_; |
| 113 }; |
| 114 |
| 115 } // namespace local_discovery |
| 116 |
| 117 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H
_ |
OLD | NEW |