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_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_
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 "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h"
14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "net/url_request/url_request_context.h"
17 #include "webkit/browser/fileapi/async_file_util.h"
18 #include "webkit/browser/fileapi/file_system_url.h"
20 namespace local_discovery
{
22 class PrivetFileSystemAsyncOperation
{
24 virtual ~PrivetFileSystemAsyncOperation() {}
26 virtual void Start() = 0;
29 class PrivetFileSystemAsyncOperationContainer
{
31 virtual ~PrivetFileSystemAsyncOperationContainer() {}
33 virtual void RemoveOperation(
34 PrivetFileSystemAsyncOperation
* operation
) = 0;
35 virtual void RemoveAllOperations() = 0;
38 // This object is a counterpart to PrivetFileSystemAsyncUtil that lives on the
40 class PrivetFileSystemOperationFactory
41 : public PrivetFileSystemAsyncOperationContainer
{
43 explicit PrivetFileSystemOperationFactory(
44 content::BrowserContext
* browser_context
);
45 virtual ~PrivetFileSystemOperationFactory();
47 void GetFileInfo(const storage::FileSystemURL
& url
,
48 const storage::AsyncFileUtil::GetFileInfoCallback
& callback
);
50 const storage::FileSystemURL
& url
,
51 const storage::AsyncFileUtil::ReadDirectoryCallback
& callback
);
53 base::WeakPtr
<PrivetFileSystemOperationFactory
> GetWeakPtr() {
54 return weak_factory_
.GetWeakPtr();
58 virtual void RemoveOperation(PrivetFileSystemAsyncOperation
* operation
)
60 virtual void RemoveAllOperations() OVERRIDE
;
62 PrivetFileSystemAttributeCache attribute_cache_
;
63 std::set
<PrivetFileSystemAsyncOperation
*> async_operations_
;
64 content::BrowserContext
* browser_context_
;
65 base::WeakPtrFactory
<PrivetFileSystemOperationFactory
> weak_factory_
;
68 class PrivetFileSystemAsyncOperationUtil
{
73 virtual ~Delegate() {}
75 // |http_client| is the client for the resolved service, or NULL if
76 // resolution failed. |path| is the canonical path within the privet
78 virtual void PrivetFileSystemResolved(PrivetV1HTTPClient
* http_client
,
79 const std::string
& path
) = 0;
82 PrivetFileSystemAsyncOperationUtil(const base::FilePath
& full_path
,
83 content::BrowserContext
* browser_context
,
85 ~PrivetFileSystemAsyncOperationUtil();
90 void OnGotDeviceDescription(bool success
,
91 const DeviceDescription
& device_description
);
92 void OnGotPrivetHTTP(scoped_ptr
<PrivetHTTPClient
> privet_http_client
);
94 ParsedPrivetPath parsed_path_
;
95 scoped_refptr
<net::URLRequestContextGetter
> request_context_
;
96 content::BrowserContext
* browser_context_
;
99 scoped_refptr
<ServiceDiscoverySharedClient
> service_discovery_client_
;
100 scoped_ptr
<PrivetDeviceResolver
> privet_device_resolver_
;
101 scoped_ptr
<PrivetHTTPAsynchronousFactory
> privet_async_factory_
;
102 scoped_ptr
<PrivetHTTPResolution
> privet_http_resolution_
;
103 scoped_ptr
<PrivetV1HTTPClient
> privet_client_
;
105 base::WeakPtrFactory
<PrivetFileSystemAsyncOperationUtil
> weak_factory_
;
108 class PrivetFileSystemListOperation
109 : public PrivetFileSystemAsyncOperationUtil::Delegate
,
110 public local_discovery::PrivetFileSystemAsyncOperation
{
112 PrivetFileSystemListOperation(
113 const base::FilePath
& full_path
,
114 content::BrowserContext
* browser_context
,
115 PrivetFileSystemAsyncOperationContainer
* container
,
116 PrivetFileSystemAttributeCache
* attribute_cache
,
117 const storage::AsyncFileUtil::ReadDirectoryCallback
& callback
);
118 virtual ~PrivetFileSystemListOperation();
120 virtual void Start() OVERRIDE
;
122 virtual void PrivetFileSystemResolved(PrivetV1HTTPClient
* http_client
,
123 const std::string
& path
) OVERRIDE
;
126 void OnStorageListResult(const base::DictionaryValue
* value
);
128 void TriggerCallbackAndDestroy(
129 base::File::Error result
,
130 const storage::AsyncFileUtil::EntryList
& file_list
,
133 PrivetFileSystemAsyncOperationUtil core_
;
134 base::FilePath full_path_
;
135 PrivetFileSystemAsyncOperationContainer
* container_
;
136 PrivetFileSystemAttributeCache
* attribute_cache_
;
137 storage::AsyncFileUtil::ReadDirectoryCallback callback_
;
139 scoped_ptr
<PrivetJSONOperation
> list_operation_
;
142 class PrivetFileSystemDetailsOperation
143 : public PrivetFileSystemAsyncOperationUtil::Delegate
,
144 public local_discovery::PrivetFileSystemAsyncOperation
{
146 PrivetFileSystemDetailsOperation(
147 const base::FilePath
& full_path
,
148 content::BrowserContext
* browser_context
,
149 PrivetFileSystemAsyncOperationContainer
* container
,
150 PrivetFileSystemAttributeCache
* attribute_cache
,
151 const storage::AsyncFileUtil::GetFileInfoCallback
& callback
);
152 virtual ~PrivetFileSystemDetailsOperation();
154 virtual void Start() OVERRIDE
;
156 virtual void PrivetFileSystemResolved(PrivetV1HTTPClient
* http_client
,
157 const std::string
& path
) OVERRIDE
;
160 void OnStorageListResult(const base::DictionaryValue
* value
);
162 void TriggerCallbackAndDestroy(base::File::Error result
,
163 const base::File::Info
& info
);
165 PrivetFileSystemAsyncOperationUtil core_
;
166 base::FilePath full_path_
;
167 PrivetFileSystemAsyncOperationContainer
* container_
;
168 PrivetFileSystemAttributeCache
* attribute_cache_
;
169 storage::AsyncFileUtil::GetFileInfoCallback callback_
;
171 scoped_ptr
<PrivetJSONOperation
> list_operation_
;
174 } // namespace local_discovery
176 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_