diff options
author | noamsml <noamsml@chromium.org> | 2014-08-28 16:25:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-28 23:27:04 +0000 |
commit | ee53aabbe77593434b57544f54c3f771f37657e7 (patch) | |
tree | 4c035ae17ce282dba868d29e2b5fa3b13e71b677 /chrome/browser/local_discovery | |
parent | 62ea4420572a57354518d9081e4150889b836d88 (diff) | |
download | chromium_src-ee53aabbe77593434b57544f54c3f771f37657e7.zip chromium_src-ee53aabbe77593434b57544f54c3f771f37657e7.tar.gz chromium_src-ee53aabbe77593434b57544f54c3f771f37657e7.tar.bz2 |
Delete Privet filesystem code
The Privet filesystem code is unmaintained, and it isn't aligned with
PrivetV3. Remove it for now.
BUG=
Review URL: https://codereview.chromium.org/492693004
Cr-Commit-Position: refs/heads/master@{#292491}
Diffstat (limited to 'chrome/browser/local_discovery')
20 files changed, 0 insertions, 1519 deletions
diff --git a/chrome/browser/local_discovery/privet_http.h b/chrome/browser/local_discovery/privet_http.h index 3d02e65..6556a67d 100644 --- a/chrome/browser/local_discovery/privet_http.h +++ b/chrome/browser/local_discovery/privet_http.h @@ -209,15 +209,6 @@ class PrivetV1HTTPClient { virtual scoped_ptr<PrivetLocalPrintOperation> CreateLocalPrintOperation( PrivetLocalPrintOperation::Delegate* delegate) = 0; - // Creates operation to list files on local Privet storage. - virtual scoped_ptr<PrivetJSONOperation> CreateStorageListOperation( - const std::string& path, - const PrivetJSONOperation::ResultCallback& callback) = 0; - - // Creates operation to read data from local Privet storage. - virtual scoped_ptr<PrivetDataReadOperation> CreateStorageReadOperation( - const std::string& path, - const PrivetDataReadOperation::ResultCallback& callback) = 0; }; } // namespace local_discovery diff --git a/chrome/browser/local_discovery/privet_http_impl.cc b/chrome/browser/local_discovery/privet_http_impl.cc index ae23de6..a1db153 100644 --- a/chrome/browser/local_discovery/privet_http_impl.cc +++ b/chrome/browser/local_discovery/privet_http_impl.cc @@ -45,10 +45,6 @@ const char kPrivetContentTypePDF[] = "application/pdf"; const char kPrivetContentTypePWGRaster[] = "image/pwg-raster"; const char kPrivetContentTypeAny[] = "*/*"; -const char kPrivetStorageListPath[] = "/privet/storage/list"; -const char kPrivetStorageContentPath[] = "/privet/storage/content"; -const char kPrivetStorageParamPathFormat[] = "path=%s"; - const char kPrivetKeyJobID[] = "job_id"; const int kPrivetCancelationTimeoutSeconds = 3; @@ -929,24 +925,4 @@ PrivetV1HTTPClientImpl::CreateLocalPrintOperation( new PrivetLocalPrintOperationImpl(info_client(), delegate)); } -scoped_ptr<PrivetJSONOperation> -PrivetV1HTTPClientImpl::CreateStorageListOperation( - const std::string& path, - const PrivetJSONOperation::ResultCallback& callback) { - std::string url_param = - base::StringPrintf(kPrivetStorageParamPathFormat, path.c_str()); - return scoped_ptr<PrivetJSONOperation>(new PrivetJSONOperationImpl( - info_client(), kPrivetStorageListPath, url_param, callback)); -} - -scoped_ptr<PrivetDataReadOperation> -PrivetV1HTTPClientImpl::CreateStorageReadOperation( - const std::string& path, - const PrivetDataReadOperation::ResultCallback& callback) { - std::string url_param = - base::StringPrintf(kPrivetStorageParamPathFormat, path.c_str()); - return scoped_ptr<PrivetDataReadOperation>(new PrivetDataReadOperationImpl( - info_client(), kPrivetStorageContentPath, url_param, callback)); -} - } // namespace local_discovery diff --git a/chrome/browser/local_discovery/privet_http_impl.h b/chrome/browser/local_discovery/privet_http_impl.h index a8fc3e1..99cd93b 100644 --- a/chrome/browser/local_discovery/privet_http_impl.h +++ b/chrome/browser/local_discovery/privet_http_impl.h @@ -332,12 +332,6 @@ class PrivetV1HTTPClientImpl : public PrivetV1HTTPClient { const PrivetJSONOperation::ResultCallback& callback) OVERRIDE; virtual scoped_ptr<PrivetLocalPrintOperation> CreateLocalPrintOperation( PrivetLocalPrintOperation::Delegate* delegate) OVERRIDE; - virtual scoped_ptr<PrivetJSONOperation> CreateStorageListOperation( - const std::string& path, - const PrivetJSONOperation::ResultCallback& callback) OVERRIDE; - virtual scoped_ptr<PrivetDataReadOperation> CreateStorageReadOperation( - const std::string& path, - const PrivetDataReadOperation::ResultCallback& callback) OVERRIDE; private: PrivetHTTPClient* info_client() { return info_client_.get(); } diff --git a/chrome/browser/local_discovery/privet_http_unittest.cc b/chrome/browser/local_discovery/privet_http_unittest.cc index 32f98d5..e19bf1a 100644 --- a/chrome/browser/local_discovery/privet_http_unittest.cc +++ b/chrome/browser/local_discovery/privet_http_unittest.cc @@ -186,8 +186,6 @@ const char kSampleInvalidDocumentTypeResponse[] = "{" const char kSampleCreatejobResponse[] = "{ \"job_id\": \"1234\" }"; -const char kSampleEmptyJSONResponse[] = "{}"; - const char kSampleCJT[] = "{ \"version\" : \"1.0\" }"; const char kSampleCapabilitiesResponsePWGSettings[] = @@ -460,24 +458,6 @@ class FakePWGRasterConverter : public PWGRasterConverter { printing::PwgRasterSettings bitmap_settings_; }; -TEST_F(PrivetHTTPTest, CreatePrivetStorageList) { - MockJSONCallback mock_callback; - scoped_ptr<PrivetJSONOperation> storage_list_operation = - privet_client_->CreateStorageListOperation( - "/path/to/nothing", - mock_callback.callback()); - storage_list_operation->Start(); - - EXPECT_TRUE(SuccessfulResponseToURL(GURL("http://10.0.0.8:6006/privet/info"), - kSampleInfoResponse)); - - EXPECT_CALL(mock_callback, OnPrivetJSONDoneInternal()); - - EXPECT_TRUE(SuccessfulResponseToURL( - GURL("http://10.0.0.8:6006/privet/storage/list?path=/path/to/nothing"), - kSampleEmptyJSONResponse)); -} - class PrivetInfoTest : public PrivetHTTPTest { public: PrivetInfoTest() {} diff --git a/chrome/browser/local_discovery/storage/path_util.cc b/chrome/browser/local_discovery/storage/path_util.cc deleted file mode 100644 index 0225c9c..0000000 --- a/chrome/browser/local_discovery/storage/path_util.cc +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/path_util.h" - -#include <algorithm> - -#include "base/logging.h" -#include "base/strings/utf_string_conversions.h" - -namespace local_discovery { - -namespace { - -std::string UnescapeSlashes(const std::string& str) { - std::string output = ""; - for (size_t i = 0; i < str.length(); i++) { - if (str[i] == '$') { - i++; - switch (str[i]) { - case 's': - output += '/'; - break; - case 'b': - output += '\\'; - break; - case '$': - output += '$'; - break; - default: - NOTREACHED(); - } - } else { - output += str[i]; - } - } - - return output; -} - -const size_t kNumComponentsInBasePrivetPath = 4; -const int kIndexOfServiceNameInComponentList = 2; - -std::string PathStringToString(const base::FilePath::StringType& string) { -#if defined(OS_WIN) - return base::UTF16ToUTF8(string); -#else - return string; -#endif -} - -} // namespace - -base::FilePath NormalizeFilePath(const base::FilePath& path) { -#if defined(OS_WIN) - base::FilePath::StringType path_updated_string = path.value(); - - std::replace(path_updated_string.begin(), - path_updated_string.end(), - static_cast<base::FilePath::CharType>('\\'), - static_cast<base::FilePath::CharType>('/')); - return base::FilePath(path_updated_string); -#else - return path; -#endif -} - -ParsedPrivetPath::ParsedPrivetPath(const base::FilePath& file_path) { - std::vector<base::FilePath::StringType> components; - file_path.GetComponents(&components); - DCHECK(components.size() >= kNumComponentsInBasePrivetPath); - service_name = UnescapeSlashes(PathStringToString( - components[kIndexOfServiceNameInComponentList])); - - - for (size_t i = kNumComponentsInBasePrivetPath; i < components.size(); i++) { - path += '/' + PathStringToString(components[i]); - } - - if (path.empty()) path = "/"; -} - -ParsedPrivetPath::~ParsedPrivetPath() { -} - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/path_util.h b/chrome/browser/local_discovery/storage/path_util.h deleted file mode 100644 index 1b219d6..0000000 --- a/chrome/browser/local_discovery/storage/path_util.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PATH_UTIL_H_ -#define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PATH_UTIL_H_ - -#include "base/files/file_path.h" - -namespace local_discovery { - -base::FilePath NormalizeFilePath(const base::FilePath& path); - -struct ParsedPrivetPath { - explicit ParsedPrivetPath(const base::FilePath& path); - ~ParsedPrivetPath(); - - std::string service_name; - std::string path; -}; - - -} // namespace local_discovery - -#endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PATH_UTIL_H_ diff --git a/chrome/browser/local_discovery/storage/path_util_unittest.cc b/chrome/browser/local_discovery/storage/path_util_unittest.cc deleted file mode 100644 index cc1cf72..0000000 --- a/chrome/browser/local_discovery/storage/path_util_unittest.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/path_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace local_discovery { - -TEST(PathUtilTest, ParsePrivetPath) { - ParsedPrivetPath path(base::FilePath(FILE_PATH_LITERAL( - "/privet/MyId._privet._tcp.local/Some name/some/path"))); - - EXPECT_EQ("MyId._privet._tcp.local", path.service_name); - EXPECT_EQ("/some/path", path.path); -} - -TEST(PathUtilTest, ParseEmptyPath) { - ParsedPrivetPath path(base::FilePath(FILE_PATH_LITERAL( - "/privet/MyId._privet._tcp.local/Some name/"))); - - EXPECT_EQ("MyId._privet._tcp.local", path.service_name); - EXPECT_EQ("/", path.path); -} - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_async_util.cc b/chrome/browser/local_discovery/storage/privet_filesystem_async_util.cc deleted file mode 100644 index 9fece15..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_async_util.cc +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/privet_filesystem_async_util.h" - -#include "chrome/browser/local_discovery/storage/path_util.h" -#include "webkit/browser/fileapi/file_system_url.h" -#include "webkit/common/blob/shareable_file_reference.h" - -namespace local_discovery { - -PrivetFileSystemAsyncUtil::PrivetFileSystemAsyncUtil( - content::BrowserContext* browser_context) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - operation_factory_ = new PrivetFileSystemOperationFactory(browser_context); -} - -PrivetFileSystemAsyncUtil::~PrivetFileSystemAsyncUtil() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - content::BrowserThread::DeleteSoon( - content::BrowserThread::UI, FROM_HERE, operation_factory_); -} - -void PrivetFileSystemAsyncUtil::CreateOrOpen( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - int file_flags, - const CreateOrOpenCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File(base::File::FILE_ERROR_INVALID_OPERATION), - base::Closure()); -} - -void PrivetFileSystemAsyncUtil::EnsureFileExists( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const EnsureFileExistsCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, false); -} - -void PrivetFileSystemAsyncUtil::CreateDirectory( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - bool exclusive, - bool recursive, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::GetFileInfo( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const GetFileInfoCallback& callback) { - ParsedPrivetPath parsed_path(url.path()); - - if (parsed_path.path == "/") { - base::File::Info file_info; - file_info.is_directory = true; - file_info.is_symbolic_link = false; - callback.Run(base::File::FILE_OK, file_info); - return; - } - - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(&PrivetFileSystemOperationFactory::GetFileInfo, - operation_factory_->GetWeakPtr(), - url, - callback)); -} - -void PrivetFileSystemAsyncUtil::ReadDirectory( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const ReadDirectoryCallback& callback) { - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(&PrivetFileSystemOperationFactory::ReadDirectory, - operation_factory_->GetWeakPtr(), - url, - callback)); -} - -void PrivetFileSystemAsyncUtil::Touch( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const base::Time& last_access_time, - const base::Time& last_modified_time, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::Truncate( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - int64 length, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::CopyFileLocal( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& src_url, - const storage::FileSystemURL& dest_url, - CopyOrMoveOption option, - const CopyFileProgressCallback& progress_callback, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::MoveFileLocal( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& src_url, - const storage::FileSystemURL& dest_url, - CopyOrMoveOption option, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::CopyInForeignFile( - scoped_ptr<storage::FileSystemOperationContext> context, - const base::FilePath& src_file_path, - const storage::FileSystemURL& dest_url, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::DeleteFile( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::DeleteDirectory( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::DeleteRecursively( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const StatusCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); -} - -void PrivetFileSystemAsyncUtil::CreateSnapshotFile( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const CreateSnapshotFileCallback& callback) { - NOTIMPLEMENTED(); - callback.Run(base::File::FILE_ERROR_INVALID_OPERATION, - base::File::Info(), - base::FilePath(), - scoped_refptr<storage::ShareableFileReference>()); -} - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_async_util.h b/chrome/browser/local_discovery/storage/privet_filesystem_async_util.h deleted file mode 100644 index b190480..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_async_util.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_ASYNC_UTIL_H_ -#define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_ASYNC_UTIL_H_ - -#include "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h" -#include "chrome/browser/local_discovery/storage/privet_filesystem_operations.h" -#include "content/public/browser/browser_context.h" -#include "webkit/browser/fileapi/async_file_util.h" - -namespace local_discovery { - -class PrivetFileSystemAsyncUtil : public storage::AsyncFileUtil { - public: - explicit PrivetFileSystemAsyncUtil(content::BrowserContext* browser_context); - virtual ~PrivetFileSystemAsyncUtil(); - - virtual void CreateOrOpen( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - int file_flags, - const CreateOrOpenCallback& callback) OVERRIDE; - virtual void EnsureFileExists( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const EnsureFileExistsCallback& callback) OVERRIDE; - virtual void CreateDirectory( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - bool exclusive, - bool recursive, - const StatusCallback& callback) OVERRIDE; - virtual void GetFileInfo( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const GetFileInfoCallback& callback) OVERRIDE; - virtual void ReadDirectory( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const ReadDirectoryCallback& callback) OVERRIDE; - virtual void Touch(scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const base::Time& last_access_time, - const base::Time& last_modified_time, - const StatusCallback& callback) OVERRIDE; - virtual void Truncate(scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - int64 length, - const StatusCallback& callback) OVERRIDE; - virtual void CopyFileLocal( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& src_url, - const storage::FileSystemURL& dest_url, - CopyOrMoveOption option, - const CopyFileProgressCallback& progress_callback, - const StatusCallback& callback) OVERRIDE; - virtual void MoveFileLocal( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& src_url, - const storage::FileSystemURL& dest_url, - CopyOrMoveOption option, - const StatusCallback& callback) OVERRIDE; - virtual void CopyInForeignFile( - scoped_ptr<storage::FileSystemOperationContext> context, - const base::FilePath& src_file_path, - const storage::FileSystemURL& dest_url, - const StatusCallback& callback) OVERRIDE; - virtual void DeleteFile( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const StatusCallback& callback) OVERRIDE; - virtual void DeleteDirectory( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const StatusCallback& callback) OVERRIDE; - virtual void DeleteRecursively( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const StatusCallback& callback) OVERRIDE; - virtual void CreateSnapshotFile( - scoped_ptr<storage::FileSystemOperationContext> context, - const storage::FileSystemURL& url, - const CreateSnapshotFileCallback& callback) OVERRIDE; - - private: - PrivetFileSystemOperationFactory* operation_factory_; -}; - -} // namespace local_discovery - -#endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_ASYNC_UTIL_H_ diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.cc b/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.cc deleted file mode 100644 index d85c92a..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h" - -#include "chrome/browser/local_discovery/storage/path_util.h" -#include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" - -namespace local_discovery { - -PrivetFileSystemAttributeCache::PrivetFileSystemAttributeCache() {} - -PrivetFileSystemAttributeCache::~PrivetFileSystemAttributeCache() {} - -const base::File::Info* PrivetFileSystemAttributeCache::GetFileInfo( - const base::FilePath& full_path) { - FileInfoMap::iterator found = - file_info_map_.find(NormalizeFilePath(full_path)); - - if (found != file_info_map_.end()) { - return &found->second; - } - - return NULL; -} - -void PrivetFileSystemAttributeCache::AddFileInfoFromJSON( - const base::FilePath& full_path, - const base::DictionaryValue* json) { - AddEntryInfoFromJSON(full_path, json); - - const base::ListValue* entry_list; - if (!json->GetList(kPrivetListEntries, &entry_list)) - return; - - for (size_t i = 0; i < entry_list->GetSize(); i++) { - const base::DictionaryValue* entry_value; - if (!entry_list->GetDictionary(i, &entry_value)) - break; - - std::string name; - if (!entry_value->GetString(kPrivetListKeyName, &name)) - break; - - AddEntryInfoFromJSON(full_path.AppendASCII(name), entry_value); - } -} - -void PrivetFileSystemAttributeCache::AddEntryInfoFromJSON( - const base::FilePath& full_path, - const base::DictionaryValue* json) { - base::File::Info file_info; - - std::string type; - int size = 0; - - json->GetString(kPrivetListKeyType, &type); - json->GetInteger(kPrivetListKeySize, &size); - - file_info.size = size; - file_info.is_directory = (type == kPrivetListTypeDir); - file_info.is_symbolic_link = false; - - file_info_map_[NormalizeFilePath(full_path)] = file_info; -} - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h b/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h deleted file mode 100644 index 9b55a7e..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_ATTRIBUTE_CACHE_H_ -#define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_ATTRIBUTE_CACHE_H_ - -#include <map> - -#include "base/files/file.h" -#include "base/values.h" - -namespace local_discovery { - -class PrivetFileSystemAttributeCache { - public: - PrivetFileSystemAttributeCache(); - ~PrivetFileSystemAttributeCache(); - - // Get File info for a path in the filesystem. Returns NULL if not found. - const base::File::Info* GetFileInfo(const base::FilePath& full_path); - - // Add file info from the result of a /privet/storage/list request. - void AddFileInfoFromJSON(const base::FilePath& full_path, - const base::DictionaryValue* json); - - private: - typedef std::map<base::FilePath, base::File::Info> FileInfoMap; - - void AddEntryInfoFromJSON(const base::FilePath& full_path, - const base::DictionaryValue* json); - - FileInfoMap file_info_map_; -}; - -} // namespace local_discovery - -#endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_ATTRIBUTE_CACHE_H_ diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache_unittest.cc b/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache_unittest.cc deleted file mode 100644 index 30c660c..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache_unittest.cc +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/files/file_path.h" -#include "base/json/json_reader.h" -#include "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace local_discovery { - -namespace { - -const char kPrivetStorageJSON[] = - "{" - " \"name\": \"foo\"," - " \"type\": \"dir\"," - " \"entries\" : [ " - " { \"name\": \"bar\", \"type\": \"dir\" }," - " { \"name\": \"baz.txt\", \"type\": \"file\", \"size\": 12345 }" - " ]}"; - -class PrivetFileSystemAttributeCacheTest : public ::testing::Test { - public: - PrivetFileSystemAttributeCacheTest() {} - - virtual ~PrivetFileSystemAttributeCacheTest() {} - - PrivetFileSystemAttributeCache cache_; -}; - -TEST_F(PrivetFileSystemAttributeCacheTest, AllAdded) { - scoped_ptr<base::Value> json(base::JSONReader::Read(kPrivetStorageJSON)); - const base::DictionaryValue* dictionary_json; - json->GetAsDictionary(&dictionary_json); - - cache_.AddFileInfoFromJSON( - base::FilePath(FILE_PATH_LITERAL("/test/path/foo")), dictionary_json); - - const base::File::Info* info_foo = - cache_.GetFileInfo(base::FilePath(FILE_PATH_LITERAL("/test/path/foo"))); - EXPECT_TRUE(info_foo->is_directory); - EXPECT_FALSE(info_foo->is_symbolic_link); - - const base::File::Info* info_bar = cache_.GetFileInfo( - base::FilePath(FILE_PATH_LITERAL("/test/path/foo/bar"))); - EXPECT_TRUE(info_bar->is_directory); - EXPECT_FALSE(info_bar->is_symbolic_link); - - const base::File::Info* info_baz = cache_.GetFileInfo( - base::FilePath(FILE_PATH_LITERAL("/test/path/foo/baz.txt"))); - EXPECT_FALSE(info_baz->is_directory); - EXPECT_FALSE(info_baz->is_symbolic_link); - EXPECT_EQ(12345, info_baz->size); - - const base::File::Info* info_notfound = cache_.GetFileInfo( - base::FilePath(FILE_PATH_LITERAL("/test/path/foo/notfound.txt"))); - EXPECT_EQ(NULL, info_notfound); -} - -} // namespace - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_backend.cc b/chrome/browser/local_discovery/storage/privet_filesystem_backend.cc deleted file mode 100644 index 9abfcaf..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_backend.cc +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/privet_filesystem_backend.h" - -#include <string> - -#include "chrome/browser/local_discovery/storage/privet_filesystem_async_util.h" -#include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" -#include "webkit/browser/fileapi/file_system_operation.h" -#include "webkit/browser/fileapi/file_system_url.h" - -namespace local_discovery { - -PrivetFileSystemBackend::PrivetFileSystemBackend( - storage::ExternalMountPoints* mount_points, - content::BrowserContext* browser_context) - : mount_points_(mount_points), - async_util_(new PrivetFileSystemAsyncUtil(browser_context)) { -} - -PrivetFileSystemBackend::~PrivetFileSystemBackend() { -} - -bool PrivetFileSystemBackend::CanHandleType( - storage::FileSystemType type) const { - return (type == storage::kFileSystemTypeCloudDevice); -} - -void PrivetFileSystemBackend::Initialize(storage::FileSystemContext* context) { - mount_points_->RegisterFileSystem("privet", - storage::kFileSystemTypeCloudDevice, - storage::FileSystemMountOption(), - base::FilePath(kPrivetFilePath)); -} - -void PrivetFileSystemBackend::ResolveURL( - const storage::FileSystemURL& url, - storage::OpenFileSystemMode mode, - const OpenFileSystemCallback& callback) { - // TODO(noamsml): Provide a proper root url and a proper name. - GURL root_url = GURL( - storage::GetExternalFileSystemRootURIString(url.origin(), std::string())); - callback.Run(root_url, std::string(), base::File::FILE_OK); -} - -storage::FileSystemQuotaUtil* PrivetFileSystemBackend::GetQuotaUtil() { - // No quota support. - return NULL; -} - -storage::AsyncFileUtil* PrivetFileSystemBackend::GetAsyncFileUtil( - storage::FileSystemType type) { - return async_util_.get(); -} - -storage::WatcherManager* PrivetFileSystemBackend::GetWatcherManager( - storage::FileSystemType type) { - return NULL; -} - -storage::CopyOrMoveFileValidatorFactory* -PrivetFileSystemBackend::GetCopyOrMoveFileValidatorFactory( - storage::FileSystemType type, - base::File::Error* error_code) { - DCHECK(error_code); - *error_code = base::File::FILE_OK; - return NULL; -} - -storage::FileSystemOperation* -PrivetFileSystemBackend::CreateFileSystemOperation( - const storage::FileSystemURL& url, - storage::FileSystemContext* context, - base::File::Error* error_code) const { - return storage::FileSystemOperation::Create( - url, - context, - make_scoped_ptr(new storage::FileSystemOperationContext(context))); -} - -bool PrivetFileSystemBackend::SupportsStreaming( - const storage::FileSystemURL& url) const { - return false; -} - -bool PrivetFileSystemBackend::HasInplaceCopyImplementation( - storage::FileSystemType type) const { - return true; -} - -scoped_ptr<storage::FileStreamReader> -PrivetFileSystemBackend::CreateFileStreamReader( - const storage::FileSystemURL& url, - int64 offset, - const base::Time& expected_modification_time, - storage::FileSystemContext* context) const { - return scoped_ptr<storage::FileStreamReader>(); -} - -scoped_ptr<storage::FileStreamWriter> -PrivetFileSystemBackend::CreateFileStreamWriter( - const storage::FileSystemURL& url, - int64 offset, - storage::FileSystemContext* context) const { - return scoped_ptr<storage::FileStreamWriter>(); -} - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_backend.h b/chrome/browser/local_discovery/storage/privet_filesystem_backend.h deleted file mode 100644 index bed35d7..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_backend.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_BACKEND_H_ -#define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_BACKEND_H_ - -#include <string> -#include <vector> - -#include "base/memory/ref_counted.h" -#include "content/public/browser/browser_context.h" -#include "webkit/browser/blob/file_stream_reader.h" -#include "webkit/browser/fileapi/external_mount_points.h" -#include "webkit/browser/fileapi/file_stream_writer.h" -#include "webkit/browser/fileapi/file_system_backend.h" - -namespace local_discovery { - -class PrivetFileSystemAsyncUtil; - -class PrivetFileSystemBackend : public storage::FileSystemBackend { - public: - PrivetFileSystemBackend(storage::ExternalMountPoints* mount_points, - content::BrowserContext* browser_context); - virtual ~PrivetFileSystemBackend(); - - // FileSystemBackend implementation. - virtual bool CanHandleType(storage::FileSystemType type) const OVERRIDE; - virtual void Initialize(storage::FileSystemContext* context) OVERRIDE; - - virtual void ResolveURL(const storage::FileSystemURL& url, - storage::OpenFileSystemMode mode, - const OpenFileSystemCallback& callback) OVERRIDE; - - virtual storage::AsyncFileUtil* GetAsyncFileUtil( - storage::FileSystemType type) OVERRIDE; - virtual storage::WatcherManager* GetWatcherManager( - storage::FileSystemType type) OVERRIDE; - virtual storage::CopyOrMoveFileValidatorFactory* - GetCopyOrMoveFileValidatorFactory(storage::FileSystemType type, - base::File::Error* error_code) OVERRIDE; - - virtual storage::FileSystemOperation* CreateFileSystemOperation( - const storage::FileSystemURL& url, - storage::FileSystemContext* context, - base::File::Error* error_code) const OVERRIDE; - - virtual bool SupportsStreaming( - const storage::FileSystemURL& url) const OVERRIDE; - - virtual bool HasInplaceCopyImplementation( - storage::FileSystemType type) const OVERRIDE; - - virtual scoped_ptr<storage::FileStreamReader> CreateFileStreamReader( - const storage::FileSystemURL& url, - int64 offset, - const base::Time& expected_modification_time, - storage::FileSystemContext* context) const OVERRIDE; - - virtual scoped_ptr<storage::FileStreamWriter> CreateFileStreamWriter( - const storage::FileSystemURL& url, - int64 offset, - storage::FileSystemContext* context) const OVERRIDE; - - virtual storage::FileSystemQuotaUtil* GetQuotaUtil() OVERRIDE; - - private: - // User mount points. - scoped_refptr<storage::ExternalMountPoints> mount_points_; - scoped_ptr<PrivetFileSystemAsyncUtil> async_util_; -}; - -} // namespace local_discovery - -#endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_BACKEND_H_ diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_constants.cc b/chrome/browser/local_discovery/storage/privet_filesystem_constants.cc deleted file mode 100644 index 80b59d3..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_constants.cc +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" - -namespace local_discovery { - -const base::FilePath::CharType kPrivetFilePath[] = FILE_PATH_LITERAL("/privet"); -const char kPrivetTypeStorage[] = "storage"; - -const char kPrivetListEntries[] = "entries"; -const char kPrivetListKeyName[] = "name"; -const char kPrivetListKeySize[] = "size"; -const char kPrivetListKeyType[] = "type"; -const char kPrivetListTypeDir[] = "dir"; - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_constants.h b/chrome/browser/local_discovery/storage/privet_filesystem_constants.h deleted file mode 100644 index 179b1c6..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_constants.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_CONSTANTS_H_ -#define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_CONSTANTS_H_ - -#include "base/files/file_path.h" - -namespace local_discovery { - -extern const base::FilePath::CharType kPrivetFilePath[]; -extern const char kPrivetTypeStorage[]; - -extern const char kPrivetListEntries[]; -extern const char kPrivetListKeyName[]; -extern const char kPrivetListKeySize[]; -extern const char kPrivetListKeyType[]; -extern const char kPrivetListTypeDir[]; - -} // namespace local_discovery - -#endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_CONSTANTS_H_ diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_operations.cc b/chrome/browser/local_discovery/storage/privet_filesystem_operations.cc deleted file mode 100644 index 1439218..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_operations.cc +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/privet_filesystem_operations.h" - -#include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" - -namespace local_discovery { - -PrivetFileSystemOperationFactory::PrivetFileSystemOperationFactory( - content::BrowserContext* browser_context) - : browser_context_(browser_context), weak_factory_(this) {} - -PrivetFileSystemOperationFactory::~PrivetFileSystemOperationFactory() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - RemoveAllOperations(); -} - -void PrivetFileSystemOperationFactory::GetFileInfo( - const storage::FileSystemURL& url, - const storage::AsyncFileUtil::GetFileInfoCallback& callback) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - PrivetFileSystemAsyncOperation* operation = - new PrivetFileSystemDetailsOperation( - url.path(), browser_context_, this, &attribute_cache_, callback); - async_operations_.insert(operation); - operation->Start(); -} - -void PrivetFileSystemOperationFactory::ReadDirectory( - const storage::FileSystemURL& url, - const storage::AsyncFileUtil::ReadDirectoryCallback& callback) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - PrivetFileSystemAsyncOperation* operation = new PrivetFileSystemListOperation( - url.path(), browser_context_, this, &attribute_cache_, callback); - async_operations_.insert(operation); - operation->Start(); -} - -void PrivetFileSystemOperationFactory::RemoveOperation( - PrivetFileSystemAsyncOperation* operation) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - async_operations_.erase(operation); - delete operation; -} - -void PrivetFileSystemOperationFactory::RemoveAllOperations() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - STLDeleteElements(&async_operations_); -} - -PrivetFileSystemAsyncOperationUtil::PrivetFileSystemAsyncOperationUtil( - const base::FilePath& full_path, - content::BrowserContext* browser_context, - Delegate* delegate) - : parsed_path_(full_path), - browser_context_(browser_context), - delegate_(delegate), - weak_factory_(this) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); -} - -PrivetFileSystemAsyncOperationUtil::~PrivetFileSystemAsyncOperationUtil() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); -} - -void PrivetFileSystemAsyncOperationUtil::Start() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - request_context_ = browser_context_->GetRequestContext(); - service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); - privet_device_resolver_.reset(new PrivetDeviceResolver( - service_discovery_client_.get(), - parsed_path_.service_name, - base::Bind( - &PrivetFileSystemAsyncOperationUtil::OnGotDeviceDescription, - base::Unretained(this)))); - privet_device_resolver_->Start(); -} - -void PrivetFileSystemAsyncOperationUtil::OnGotDeviceDescription( - bool success, const DeviceDescription& device_description) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - if (!success) { - delegate_->PrivetFileSystemResolved(NULL, parsed_path_.path); - return; - } - - privet_async_factory_ = PrivetHTTPAsynchronousFactory::CreateInstance( - service_discovery_client_.get(), request_context_.get()); - privet_http_resolution_ = privet_async_factory_->CreatePrivetHTTP( - parsed_path_.service_name, - device_description.address, - base::Bind(&PrivetFileSystemAsyncOperationUtil::OnGotPrivetHTTP, - base::Unretained(this))); - privet_http_resolution_->Start(); -} - -void PrivetFileSystemAsyncOperationUtil::OnGotPrivetHTTP( - scoped_ptr<PrivetHTTPClient> privet_http_client) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - privet_client_ = PrivetV1HTTPClient::CreateDefault(privet_http_client.Pass()); - delegate_->PrivetFileSystemResolved(privet_client_.get(), - parsed_path_.path); -} - -PrivetFileSystemListOperation::PrivetFileSystemListOperation( - const base::FilePath& full_path, - content::BrowserContext* browser_context, - PrivetFileSystemAsyncOperationContainer* container, - PrivetFileSystemAttributeCache* attribute_cache, - const storage::AsyncFileUtil::ReadDirectoryCallback& callback) - : core_(full_path, browser_context, this), - full_path_(full_path), - container_(container), - attribute_cache_(attribute_cache), - callback_(callback) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); -} - -PrivetFileSystemListOperation::~PrivetFileSystemListOperation() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); -} - -void PrivetFileSystemListOperation::Start() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - core_.Start(); -} - -void PrivetFileSystemListOperation::PrivetFileSystemResolved( - PrivetV1HTTPClient* http_client, - const std::string& path) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - if (!http_client) { - SignalError(); - return; - } - - list_operation_ = http_client->CreateStorageListOperation( - path, - base::Bind(&PrivetFileSystemListOperation::OnStorageListResult, - base::Unretained(this))); - list_operation_->Start(); -} - -void PrivetFileSystemListOperation::OnStorageListResult( - const base::DictionaryValue* value) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - list_operation_.reset(); - - if (!value) { - SignalError(); - return; - } - - attribute_cache_->AddFileInfoFromJSON(full_path_, value); - - storage::AsyncFileUtil::EntryList entry_list; - - const base::ListValue* entries; - if (!value->GetList(kPrivetListEntries, &entries)) { - SignalError(); - return; - } - - for (size_t i = 0; i < entries->GetSize(); i++) { - const base::DictionaryValue* entry_value; - if (!entries->GetDictionary(i, &entry_value)) { - SignalError(); - return; - } - - std::string name; - std::string type; - int size = 0; - - entry_value->GetString(kPrivetListKeyName, &name); - entry_value->GetString(kPrivetListKeyType, &type); - entry_value->GetInteger(kPrivetListKeySize, &size); - - storage::DirectoryEntry entry(name, - (type == kPrivetListTypeDir) - ? storage::DirectoryEntry::DIRECTORY - : storage::DirectoryEntry::FILE, - size, - base::Time() /* TODO(noamsml) */); - - entry_list.push_back(entry); - } - - TriggerCallbackAndDestroy(base::File::FILE_OK, entry_list, false); -} - -void PrivetFileSystemListOperation::SignalError() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - TriggerCallbackAndDestroy(base::File::FILE_ERROR_FAILED, - storage::AsyncFileUtil::EntryList(), - false); -} - -void PrivetFileSystemListOperation::TriggerCallbackAndDestroy( - base::File::Error result, - const storage::AsyncFileUtil::EntryList& file_list, - bool has_more) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - content::BrowserThread::PostTask( - content::BrowserThread::IO, - FROM_HERE, - base::Bind(callback_, result, file_list, has_more)); - container_->RemoveOperation(this); -} - -PrivetFileSystemDetailsOperation::PrivetFileSystemDetailsOperation( - const base::FilePath& full_path, - content::BrowserContext* browser_context, - PrivetFileSystemAsyncOperationContainer* container, - PrivetFileSystemAttributeCache* attribute_cache, - const storage::AsyncFileUtil::GetFileInfoCallback& callback) - : core_(full_path, browser_context, this), - full_path_(full_path), - container_(container), - attribute_cache_(attribute_cache), - callback_(callback) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); -} - -PrivetFileSystemDetailsOperation::~PrivetFileSystemDetailsOperation() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); -} - -void PrivetFileSystemDetailsOperation::Start() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - const base::File::Info* info = attribute_cache_->GetFileInfo(full_path_); - if (info) { - TriggerCallbackAndDestroy(base::File::FILE_OK, *info); - return; - } - - core_.Start(); -} - -void PrivetFileSystemDetailsOperation::PrivetFileSystemResolved( - PrivetV1HTTPClient* http_client, - const std::string& path) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - if (!http_client) { - SignalError(); - return; - } - - list_operation_ = http_client->CreateStorageListOperation( - path, - base::Bind(&PrivetFileSystemDetailsOperation::OnStorageListResult, - base::Unretained(this))); - list_operation_->Start(); -} - -void PrivetFileSystemDetailsOperation::OnStorageListResult( - const base::DictionaryValue* value) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - list_operation_.reset(); - - attribute_cache_->AddFileInfoFromJSON(full_path_, value); - const base::File::Info* info = attribute_cache_->GetFileInfo(full_path_); - - if (info) { - TriggerCallbackAndDestroy(base::File::FILE_OK, *info); - } else { - SignalError(); - } -} - -void PrivetFileSystemDetailsOperation::SignalError() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - TriggerCallbackAndDestroy(base::File::FILE_ERROR_FAILED, base::File::Info()); -} - -void PrivetFileSystemDetailsOperation::TriggerCallbackAndDestroy( - base::File::Error result, - const base::File::Info& info) { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - content::BrowserThread::PostTask(content::BrowserThread::IO, - FROM_HERE, - base::Bind(callback_, result, info)); - container_->RemoveOperation(this); -} - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_filesystem_operations.h b/chrome/browser/local_discovery/storage/privet_filesystem_operations.h deleted file mode 100644 index c1a92b5..0000000 --- a/chrome/browser/local_discovery/storage/privet_filesystem_operations.h +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_ -#define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_ - -#include "chrome/browser/local_discovery/privet_device_resolver.h" -#include "chrome/browser/local_discovery/privet_http.h" -#include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" -#include "chrome/browser/local_discovery/service_discovery_shared_client.h" -#include "chrome/browser/local_discovery/storage/path_util.h" -#include "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_thread.h" -#include "net/url_request/url_request_context.h" -#include "webkit/browser/fileapi/async_file_util.h" -#include "webkit/browser/fileapi/file_system_url.h" - -namespace local_discovery { - -class PrivetFileSystemAsyncOperation { - public: - virtual ~PrivetFileSystemAsyncOperation() {} - - virtual void Start() = 0; -}; - -class PrivetFileSystemAsyncOperationContainer { - public: - virtual ~PrivetFileSystemAsyncOperationContainer() {} - - virtual void RemoveOperation( - PrivetFileSystemAsyncOperation* operation) = 0; - virtual void RemoveAllOperations() = 0; -}; - -// This object is a counterpart to PrivetFileSystemAsyncUtil that lives on the -// UI thread. -class PrivetFileSystemOperationFactory - : public PrivetFileSystemAsyncOperationContainer { - public: - explicit PrivetFileSystemOperationFactory( - content::BrowserContext* browser_context); - virtual ~PrivetFileSystemOperationFactory(); - - void GetFileInfo(const storage::FileSystemURL& url, - const storage::AsyncFileUtil::GetFileInfoCallback& callback); - void ReadDirectory( - const storage::FileSystemURL& url, - const storage::AsyncFileUtil::ReadDirectoryCallback& callback); - - base::WeakPtr<PrivetFileSystemOperationFactory> GetWeakPtr() { - return weak_factory_.GetWeakPtr(); - } - - private: - virtual void RemoveOperation(PrivetFileSystemAsyncOperation* operation) - OVERRIDE; - virtual void RemoveAllOperations() OVERRIDE; - - PrivetFileSystemAttributeCache attribute_cache_; - std::set<PrivetFileSystemAsyncOperation*> async_operations_; - content::BrowserContext* browser_context_; - base::WeakPtrFactory<PrivetFileSystemOperationFactory> weak_factory_; -}; - -class PrivetFileSystemAsyncOperationUtil { - public: - class Delegate { - public: - Delegate() {} - virtual ~Delegate() {} - - // |http_client| is the client for the resolved service, or NULL if - // resolution failed. |path| is the canonical path within the privet - // service. - virtual void PrivetFileSystemResolved(PrivetV1HTTPClient* http_client, - const std::string& path) = 0; - }; - - PrivetFileSystemAsyncOperationUtil(const base::FilePath& full_path, - content::BrowserContext* browser_context, - Delegate* delegate); - ~PrivetFileSystemAsyncOperationUtil(); - - void Start(); - - private: - void OnGotDeviceDescription(bool success, - const DeviceDescription& device_description); - void OnGotPrivetHTTP(scoped_ptr<PrivetHTTPClient> privet_http_client); - - ParsedPrivetPath parsed_path_; - scoped_refptr<net::URLRequestContextGetter> request_context_; - content::BrowserContext* browser_context_; - Delegate* delegate_; - - scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_; - scoped_ptr<PrivetDeviceResolver> privet_device_resolver_; - scoped_ptr<PrivetHTTPAsynchronousFactory> privet_async_factory_; - scoped_ptr<PrivetHTTPResolution> privet_http_resolution_; - scoped_ptr<PrivetV1HTTPClient> privet_client_; - - base::WeakPtrFactory<PrivetFileSystemAsyncOperationUtil> weak_factory_; -}; - -class PrivetFileSystemListOperation - : public PrivetFileSystemAsyncOperationUtil::Delegate, - public local_discovery::PrivetFileSystemAsyncOperation { - public: - PrivetFileSystemListOperation( - const base::FilePath& full_path, - content::BrowserContext* browser_context, - PrivetFileSystemAsyncOperationContainer* container, - PrivetFileSystemAttributeCache* attribute_cache, - const storage::AsyncFileUtil::ReadDirectoryCallback& callback); - virtual ~PrivetFileSystemListOperation(); - - virtual void Start() OVERRIDE; - - virtual void PrivetFileSystemResolved(PrivetV1HTTPClient* http_client, - const std::string& path) OVERRIDE; - - private: - void OnStorageListResult(const base::DictionaryValue* value); - void SignalError(); - void TriggerCallbackAndDestroy( - base::File::Error result, - const storage::AsyncFileUtil::EntryList& file_list, - bool has_more); - - PrivetFileSystemAsyncOperationUtil core_; - base::FilePath full_path_; - PrivetFileSystemAsyncOperationContainer* container_; - PrivetFileSystemAttributeCache* attribute_cache_; - storage::AsyncFileUtil::ReadDirectoryCallback callback_; - - scoped_ptr<PrivetJSONOperation> list_operation_; -}; - -class PrivetFileSystemDetailsOperation - : public PrivetFileSystemAsyncOperationUtil::Delegate, - public local_discovery::PrivetFileSystemAsyncOperation { - public: - PrivetFileSystemDetailsOperation( - const base::FilePath& full_path, - content::BrowserContext* browser_context, - PrivetFileSystemAsyncOperationContainer* container, - PrivetFileSystemAttributeCache* attribute_cache, - const storage::AsyncFileUtil::GetFileInfoCallback& callback); - virtual ~PrivetFileSystemDetailsOperation(); - - virtual void Start() OVERRIDE; - - virtual void PrivetFileSystemResolved(PrivetV1HTTPClient* http_client, - const std::string& path) OVERRIDE; - - private: - void OnStorageListResult(const base::DictionaryValue* value); - void SignalError(); - void TriggerCallbackAndDestroy(base::File::Error result, - const base::File::Info& info); - - PrivetFileSystemAsyncOperationUtil core_; - base::FilePath full_path_; - PrivetFileSystemAsyncOperationContainer* container_; - PrivetFileSystemAttributeCache* attribute_cache_; - storage::AsyncFileUtil::GetFileInfoCallback callback_; - - scoped_ptr<PrivetJSONOperation> list_operation_; -}; - -} // namespace local_discovery - -#endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_FILESYSTEM_OPERATIONS_H_ diff --git a/chrome/browser/local_discovery/storage/privet_volume_lister.cc b/chrome/browser/local_discovery/storage/privet_volume_lister.cc deleted file mode 100644 index cc387eb..0000000 --- a/chrome/browser/local_discovery/storage/privet_volume_lister.cc +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/local_discovery/storage/privet_volume_lister.h" - -#include "base/bind.h" -#include "base/message_loop/message_loop.h" -#include "base/time/time.h" -#include "chrome/browser/local_discovery/storage/privet_filesystem_constants.h" - -#if defined(ENABLE_SERVICE_DISCOVERY) -#include "chrome/browser/local_discovery/privet_device_lister_impl.h" -#endif - -namespace local_discovery { - -namespace { - -#if defined(ENABLE_SERVICE_DISCOVERY) -const int kVolumeSearchDurationMs = 10000; - -std::string EscapeSlashes(const std::string& str) { - std::string output = ""; - for (size_t i = 0; i < str.length(); i++) { - switch (str[i]) { - case '/': - output += "$s"; - break; - case '\\': - output += "$b"; - break; - case '$': - output += "$$"; - break; - default: - output += str[i]; - } - } - - return output; -} - -std::string RemoveSlashes(const std::string& str) { - std::string output = ""; - for (size_t i = 0; i < str.length(); i++) { - switch (str[i]) { - case '/': - case '\\': - break; - default: - output += str[i]; - } - } - - return output; -} -#endif // ENABLE_SERVICE_DISCOVERY - -} // namespace - -PrivetVolumeLister::PrivetVolumeLister(const ResultCallback& callback) - : callback_(callback), weak_factory_(this) { -} - -PrivetVolumeLister::~PrivetVolumeLister() { -} - -void PrivetVolumeLister::Start() { -#if defined(ENABLE_SERVICE_DISCOVERY) - service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); - privet_lister_.reset( - new PrivetDeviceListerImpl(service_discovery_client_.get(), this)); - privet_lister_->Start(); - privet_lister_->DiscoverNewDevices(false); - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - base::Bind(&PrivetVolumeLister::FinishSearch, - weak_factory_.GetWeakPtr()), - base::TimeDelta::FromMilliseconds(kVolumeSearchDurationMs)); -#else - callback_.Run(std::vector<VolumeInfo>()); -#endif -} - -#if defined(ENABLE_SERVICE_DISCOVERY) -void PrivetVolumeLister::DeviceChanged(bool added, - const std::string& name, - const DeviceDescription& description) { - if (added && description.type == kPrivetTypeStorage) { - VolumeInfo volume_info; - volume_info.volume_id = name; - volume_info.volume_label = description.name; - base::FilePath mount_root = base::FilePath( - local_discovery::kPrivetFilePath); - - // HACK(noamsml): Add extra dummy folder with the volume label so that the - // file browser displays the correct volume label. - - std::string volume_id = EscapeSlashes(volume_info.volume_id); - std::string volume_label = RemoveSlashes(volume_info.volume_label); - - volume_info.volume_path = - mount_root.AppendASCII(volume_id).AppendASCII(volume_label); - available_volumes_.push_back(volume_info); - } -} - -void PrivetVolumeLister::DeviceRemoved(const std::string& name) { -} - -void PrivetVolumeLister::DeviceCacheFlushed() { -} - -void PrivetVolumeLister::FinishSearch() { - privet_lister_.reset(); - service_discovery_client_ = NULL; - available_volumes_.swap(canonical_volume_list_); - callback_.Run(canonical_volume_list_); -} -#endif - -} // namespace local_discovery diff --git a/chrome/browser/local_discovery/storage/privet_volume_lister.h b/chrome/browser/local_discovery/storage/privet_volume_lister.h deleted file mode 100644 index 53f2e89..0000000 --- a/chrome/browser/local_discovery/storage/privet_volume_lister.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_VOLUME_LISTER_H_ -#define CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_VOLUME_LISTER_H_ - -#include <string> -#include <vector> - -#include "base/callback.h" -#include "base/files/file_path.h" -#include "base/memory/weak_ptr.h" - -#if defined(ENABLE_SERVICE_DISCOVERY) -#include "chrome/browser/local_discovery/privet_device_lister.h" -#include "chrome/browser/local_discovery/service_discovery_shared_client.h" -#endif - -namespace local_discovery { - -// This class will eventually list all of the user's Privet storage devices, -// but during prototyping phase searches the local network for Privet storage -// devices. -#if defined(ENABLE_SERVICE_DISCOVERY) -class PrivetVolumeLister : public PrivetDeviceLister::Delegate { -#else -class PrivetVolumeLister { -#endif - public: - struct VolumeInfo { - std::string volume_id; - std::string volume_label; - base::FilePath volume_path; - }; - - typedef std::vector<VolumeInfo> VolumeList; - typedef base::Callback<void(const VolumeList&)> ResultCallback; - - explicit PrivetVolumeLister(const ResultCallback& callback); - virtual ~PrivetVolumeLister(); - - void Start(); - - const std::vector<VolumeInfo>& volume_list() const { - return canonical_volume_list_; - } - -#if defined(ENABLE_SERVICE_DISCOVERY) - virtual void DeviceChanged(bool added, - const std::string& name, - const DeviceDescription& description) OVERRIDE; - virtual void DeviceRemoved(const std::string& name) OVERRIDE; - virtual void DeviceCacheFlushed() OVERRIDE; -#endif - - private: -#if defined(ENABLE_SERVICE_DISCOVERY) - void FinishSearch(); - - scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_; - scoped_ptr<PrivetDeviceLister> privet_lister_; -#endif - - std::vector<VolumeInfo> available_volumes_; - std::vector<VolumeInfo> canonical_volume_list_; - ResultCallback callback_; - base::WeakPtrFactory<PrivetVolumeLister> weak_factory_; -}; - -} // namespace local_discovery - -#endif // CHROME_BROWSER_LOCAL_DISCOVERY_STORAGE_PRIVET_VOLUME_LISTER_H_ |