| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/file_system_provider/service.h" | 5 #include "chrome/browser/chromeos/file_system_provider/service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" | 18 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" |
| 18 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 19 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 19 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 20 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 20 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 21 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
| 21 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h" | 22 #include "chrome/browser/chromeos/file_system_provider/registry_interface.h" |
| 22 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 23 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 23 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 24 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 24 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" | 25 #include "chrome/common/extensions/api/file_system_provider_capabilities/file_sy
stem_provider_capabilities_handler.h" |
| 25 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 const std::string& file_system_id) override { | 114 const std::string& file_system_id) override { |
| 114 if (!file_system_info_.get() || !watchers_.get()) | 115 if (!file_system_info_.get() || !watchers_.get()) |
| 115 return; | 116 return; |
| 116 if (file_system_info_->extension_id() == extension_id && | 117 if (file_system_info_->extension_id() == extension_id && |
| 117 file_system_info_->file_system_id() == file_system_id) { | 118 file_system_info_->file_system_id() == file_system_id) { |
| 118 file_system_info_.reset(); | 119 file_system_info_.reset(); |
| 119 watchers_.reset(); | 120 watchers_.reset(); |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 | 123 |
| 123 scoped_ptr<RestoredFileSystems> RestoreFileSystems( | 124 std::unique_ptr<RestoredFileSystems> RestoreFileSystems( |
| 124 const std::string& extension_id) override { | 125 const std::string& extension_id) override { |
| 125 scoped_ptr<RestoredFileSystems> result(new RestoredFileSystems); | 126 std::unique_ptr<RestoredFileSystems> result(new RestoredFileSystems); |
| 126 | 127 |
| 127 if (file_system_info_.get() && watchers_.get()) { | 128 if (file_system_info_.get() && watchers_.get()) { |
| 128 RestoredFileSystem restored_file_system; | 129 RestoredFileSystem restored_file_system; |
| 129 restored_file_system.extension_id = file_system_info_->extension_id(); | 130 restored_file_system.extension_id = file_system_info_->extension_id(); |
| 130 | 131 |
| 131 MountOptions options; | 132 MountOptions options; |
| 132 options.file_system_id = file_system_info_->file_system_id(); | 133 options.file_system_id = file_system_info_->file_system_id(); |
| 133 options.display_name = file_system_info_->display_name(); | 134 options.display_name = file_system_info_->display_name(); |
| 134 options.writable = file_system_info_->writable(); | 135 options.writable = file_system_info_->writable(); |
| 135 options.supports_notify_tag = file_system_info_->supports_notify_tag(); | 136 options.supports_notify_tag = file_system_info_->supports_notify_tag(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 150 ASSERT_NE(watchers_->end(), it); | 151 ASSERT_NE(watchers_->end(), it); |
| 151 it->second.last_tag = watcher.last_tag; | 152 it->second.last_tag = watcher.last_tag; |
| 152 } | 153 } |
| 153 | 154 |
| 154 const ProvidedFileSystemInfo* file_system_info() const { | 155 const ProvidedFileSystemInfo* file_system_info() const { |
| 155 return file_system_info_.get(); | 156 return file_system_info_.get(); |
| 156 } | 157 } |
| 157 const Watchers* watchers() const { return watchers_.get(); } | 158 const Watchers* watchers() const { return watchers_.get(); } |
| 158 | 159 |
| 159 private: | 160 private: |
| 160 scoped_ptr<ProvidedFileSystemInfo> file_system_info_; | 161 std::unique_ptr<ProvidedFileSystemInfo> file_system_info_; |
| 161 scoped_ptr<Watchers> watchers_; | 162 std::unique_ptr<Watchers> watchers_; |
| 162 | 163 |
| 163 DISALLOW_COPY_AND_ASSIGN(FakeRegistry); | 164 DISALLOW_COPY_AND_ASSIGN(FakeRegistry); |
| 164 }; | 165 }; |
| 165 | 166 |
| 166 // Creates a fake extension with the specified |extension_id|. | 167 // Creates a fake extension with the specified |extension_id|. |
| 167 scoped_refptr<extensions::Extension> CreateFakeExtension( | 168 scoped_refptr<extensions::Extension> CreateFakeExtension( |
| 168 const std::string& extension_id) { | 169 const std::string& extension_id) { |
| 169 base::DictionaryValue manifest; | 170 base::DictionaryValue manifest; |
| 170 std::string error; | 171 std::string error; |
| 171 manifest.SetStringWithoutPathExpansion(extensions::manifest_keys::kVersion, | 172 manifest.SetStringWithoutPathExpansion(extensions::manifest_keys::kVersion, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 199 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); | 200 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); |
| 200 extension_registry_.reset(new extensions::ExtensionRegistry(profile_)); | 201 extension_registry_.reset(new extensions::ExtensionRegistry(profile_)); |
| 201 | 202 |
| 202 service_.reset(new Service(profile_, extension_registry_.get())); | 203 service_.reset(new Service(profile_, extension_registry_.get())); |
| 203 service_->SetFileSystemFactoryForTesting( | 204 service_->SetFileSystemFactoryForTesting( |
| 204 base::Bind(&FakeProvidedFileSystem::Create)); | 205 base::Bind(&FakeProvidedFileSystem::Create)); |
| 205 extension_ = CreateFakeExtension(kExtensionId); | 206 extension_ = CreateFakeExtension(kExtensionId); |
| 206 | 207 |
| 207 registry_ = new FakeRegistry; | 208 registry_ = new FakeRegistry; |
| 208 // Passes ownership to the service instance. | 209 // Passes ownership to the service instance. |
| 209 service_->SetRegistryForTesting(make_scoped_ptr(registry_)); | 210 service_->SetRegistryForTesting(base::WrapUnique(registry_)); |
| 210 | 211 |
| 211 fake_watcher_.entry_path = base::FilePath(FILE_PATH_LITERAL("/a/b/c")); | 212 fake_watcher_.entry_path = base::FilePath(FILE_PATH_LITERAL("/a/b/c")); |
| 212 fake_watcher_.recursive = true; | 213 fake_watcher_.recursive = true; |
| 213 fake_watcher_.last_tag = "hello-world"; | 214 fake_watcher_.last_tag = "hello-world"; |
| 214 } | 215 } |
| 215 | 216 |
| 216 content::TestBrowserThreadBundle thread_bundle_; | 217 content::TestBrowserThreadBundle thread_bundle_; |
| 217 scoped_ptr<TestingProfileManager> profile_manager_; | 218 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 218 TestingProfile* profile_; | 219 TestingProfile* profile_; |
| 219 FakeChromeUserManager* user_manager_; | 220 FakeChromeUserManager* user_manager_; |
| 220 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 221 std::unique_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
| 221 scoped_ptr<extensions::ExtensionRegistry> extension_registry_; | 222 std::unique_ptr<extensions::ExtensionRegistry> extension_registry_; |
| 222 scoped_ptr<Service> service_; | 223 std::unique_ptr<Service> service_; |
| 223 scoped_refptr<extensions::Extension> extension_; | 224 scoped_refptr<extensions::Extension> extension_; |
| 224 FakeRegistry* registry_; // Owned by Service. | 225 FakeRegistry* registry_; // Owned by Service. |
| 225 Watcher fake_watcher_; | 226 Watcher fake_watcher_; |
| 226 }; | 227 }; |
| 227 | 228 |
| 228 TEST_F(FileSystemProviderServiceTest, MountFileSystem) { | 229 TEST_F(FileSystemProviderServiceTest, MountFileSystem) { |
| 229 LoggingObserver observer; | 230 LoggingObserver observer; |
| 230 service_->AddObserver(&observer); | 231 service_->AddObserver(&observer); |
| 231 | 232 |
| 232 EXPECT_EQ(base::File::FILE_OK, | 233 EXPECT_EQ(base::File::FILE_OK, |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 EXPECT_EQ(1u, observer.unmounts.size()); | 547 EXPECT_EQ(1u, observer.unmounts.size()); |
| 547 EXPECT_FALSE(registry_->file_system_info()); | 548 EXPECT_FALSE(registry_->file_system_info()); |
| 548 EXPECT_FALSE(registry_->watchers()); | 549 EXPECT_FALSE(registry_->watchers()); |
| 549 } | 550 } |
| 550 | 551 |
| 551 service_->RemoveObserver(&observer); | 552 service_->RemoveObserver(&observer); |
| 552 } | 553 } |
| 553 | 554 |
| 554 } // namespace file_system_provider | 555 } // namespace file_system_provider |
| 555 } // namespace chromeos | 556 } // namespace chromeos |
| OLD | NEW |