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 fileapi::FileSystemURL
& url
,
48 const fileapi::AsyncFileUtil::GetFileInfoCallback
& callback
);
50 const fileapi::FileSystemURL
& url
,
51 const fileapi::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(
79 PrivetHTTPClient
* http_client
,
80 const std::string
& path
) = 0;
83 PrivetFileSystemAsyncOperationUtil(const base::FilePath
& full_path
,
84 content::BrowserContext
* browser_context
,
86 ~PrivetFileSystemAsyncOperationUtil();
91 void OnGotDeviceDescription(bool success
,
92 const DeviceDescription
& device_description
);
93 void OnGotPrivetHTTP(scoped_ptr
<PrivetHTTPClient
> privet_http_client
);
95 ParsedPrivetPath parsed_path_
;
96 scoped_refptr
<net::URLRequestContextGetter
> request_context_
;
97 content::BrowserContext
* browser_context_
;
100 scoped_refptr
<ServiceDiscoverySharedClient
> service_discovery_client_
;
101 scoped_ptr
<PrivetDeviceResolver
> privet_device_resolver_
;
102 scoped_ptr
<PrivetHTTPAsynchronousFactory
> privet_async_factory_
;
103 scoped_ptr
<PrivetHTTPResolution
> privet_http_resolution_
;
104 scoped_ptr
<PrivetHTTPClient
> privet_client_
;
106 base::WeakPtrFactory
<PrivetFileSystemAsyncOperationUtil
> weak_factory_
;
109 class PrivetFileSystemListOperation
110 : public PrivetFileSystemAsyncOperationUtil::Delegate
,
111 public local_discovery::PrivetFileSystemAsyncOperation
{
113 PrivetFileSystemListOperation(
114 const base::FilePath
& full_path
,
115 content::BrowserContext
* browser_context
,
116 PrivetFileSystemAsyncOperationContainer
* container
,
117 PrivetFileSystemAttributeCache
* attribute_cache
,
118 const fileapi::AsyncFileUtil::ReadDirectoryCallback
& callback
);
119 virtual ~PrivetFileSystemListOperation();
121 virtual void Start() OVERRIDE
;
123 virtual void PrivetFileSystemResolved(
124 PrivetHTTPClient
* http_client
,
125 const std::string
& path
) OVERRIDE
;
128 void OnStorageListResult(const base::DictionaryValue
* value
);
130 void TriggerCallbackAndDestroy(
131 base::File::Error result
,
132 const fileapi::AsyncFileUtil::EntryList
& file_list
,
135 PrivetFileSystemAsyncOperationUtil core_
;
136 base::FilePath full_path_
;
137 PrivetFileSystemAsyncOperationContainer
* container_
;
138 PrivetFileSystemAttributeCache
* attribute_cache_
;
139 fileapi::AsyncFileUtil::ReadDirectoryCallback callback_
;
141 scoped_ptr
<PrivetJSONOperation
> list_operation_
;
144 class PrivetFileSystemDetailsOperation
145 : public PrivetFileSystemAsyncOperationUtil::Delegate
,
146 public local_discovery::PrivetFileSystemAsyncOperation
{
148 PrivetFileSystemDetailsOperation(
149 const base::FilePath
& full_path
,
150 content::BrowserContext
* browser_context
,
151 PrivetFileSystemAsyncOperationContainer
* container
,
152 PrivetFileSystemAttributeCache
* attribute_cache
,
153 const fileapi::AsyncFileUtil::GetFileInfoCallback
& callback
);
154 virtual ~PrivetFileSystemDetailsOperation();
156 virtual void Start() OVERRIDE
;
158 virtual void PrivetFileSystemResolved(PrivetHTTPClient
* http_client
,
159 const std::string
& path
) OVERRIDE
;
162 void OnStorageListResult(const base::DictionaryValue
* value
);
164 void TriggerCallbackAndDestroy(base::File::Error result
,
165 const base::File::Info
& info
);
167 PrivetFileSystemAsyncOperationUtil core_
;
168 base::FilePath full_path_
;
169 PrivetFileSystemAsyncOperationContainer
* container_
;
170 PrivetFileSystemAttributeCache
* attribute_cache_
;
171 fileapi::AsyncFileUtil::GetFileInfoCallback callback_
;
173 scoped_ptr
<PrivetJSONOperation
> list_operation_
;
176 } // namespace local_discovery
178 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_