OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/file_manager/job_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/job_event_router.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace file_manager { | 16 namespace file_manager { |
16 namespace { | 17 namespace { |
17 | 18 |
18 class JobEventRouterImpl : public JobEventRouter { | 19 class JobEventRouterImpl : public JobEventRouter { |
19 public: | 20 public: |
20 JobEventRouterImpl() : JobEventRouter(base::TimeDelta::FromMilliseconds(0)) { | 21 JobEventRouterImpl() : JobEventRouter(base::TimeDelta::FromMilliseconds(0)) { |
21 listener_extension_ids_.insert("extension_a"); | 22 listener_extension_ids_.insert("extension_a"); |
22 } | 23 } |
23 std::vector<linked_ptr<base::DictionaryValue>> events; | 24 std::vector<std::unique_ptr<base::DictionaryValue>> events; |
24 | 25 |
25 void SetListenerExtensionIds(std::set<std::string> extension_ids) { | 26 void SetListenerExtensionIds(std::set<std::string> extension_ids) { |
26 listener_extension_ids_ = extension_ids; | 27 listener_extension_ids_ = extension_ids; |
27 } | 28 } |
28 | 29 |
29 protected: | 30 protected: |
30 std::set<std::string> GetFileTransfersUpdateEventListenerExtensionIds() | 31 std::set<std::string> GetFileTransfersUpdateEventListenerExtensionIds() |
31 override { | 32 override { |
32 return listener_extension_ids_; | 33 return listener_extension_ids_; |
33 } | 34 } |
34 | 35 |
35 GURL ConvertDrivePathToFileSystemUrl( | 36 GURL ConvertDrivePathToFileSystemUrl( |
36 const base::FilePath& file_path, | 37 const base::FilePath& file_path, |
37 const std::string& extension_id) override { | 38 const std::string& extension_id) override { |
38 std::string url; | 39 std::string url; |
39 url.append("filesystem:chrome-extension://"); | 40 url.append("filesystem:chrome-extension://"); |
40 url.append(extension_id); | 41 url.append(extension_id); |
41 url.append(file_path.value()); | 42 url.append(file_path.value()); |
42 return GURL(url); | 43 return GURL(url); |
43 } | 44 } |
44 | 45 |
45 void DispatchEventToExtension( | 46 void DispatchEventToExtension( |
46 const std::string& extension_id, | 47 const std::string& extension_id, |
47 extensions::events::HistogramValue histogram_value, | 48 extensions::events::HistogramValue histogram_value, |
48 const std::string& event_name, | 49 const std::string& event_name, |
49 std::unique_ptr<base::ListValue> event_args) override { | 50 std::unique_ptr<base::ListValue> event_args) override { |
50 const base::DictionaryValue* event; | 51 const base::DictionaryValue* event; |
51 event_args->GetDictionary(0, &event); | 52 event_args->GetDictionary(0, &event); |
52 events.push_back(make_linked_ptr(event->DeepCopy())); | 53 events.push_back(base::WrapUnique(event->DeepCopy())); |
53 } | 54 } |
54 | 55 |
55 private: | 56 private: |
56 std::set<std::string> listener_extension_ids_; | 57 std::set<std::string> listener_extension_ids_; |
57 | 58 |
58 DISALLOW_COPY_AND_ASSIGN(JobEventRouterImpl); | 59 DISALLOW_COPY_AND_ASSIGN(JobEventRouterImpl); |
59 }; | 60 }; |
60 | 61 |
61 class JobEventRouterTest : public testing::Test { | 62 class JobEventRouterTest : public testing::Test { |
62 protected: | 63 protected: |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // Check event for extension_b. | 241 // Check event for extension_b. |
241 EXPECT_EQ("in_progress", GetEventString(1, "transferState")); | 242 EXPECT_EQ("in_progress", GetEventString(1, "transferState")); |
242 EXPECT_EQ(0.0f, GetEventDouble(1, "processed")); | 243 EXPECT_EQ(0.0f, GetEventDouble(1, "processed")); |
243 EXPECT_EQ(100.0f, GetEventDouble(1, "total")); | 244 EXPECT_EQ(100.0f, GetEventDouble(1, "total")); |
244 EXPECT_EQ("filesystem:chrome-extension://extension_b/test/a", | 245 EXPECT_EQ("filesystem:chrome-extension://extension_b/test/a", |
245 GetEventString(1, "fileUrl")); | 246 GetEventString(1, "fileUrl")); |
246 } | 247 } |
247 | 248 |
248 } // namespace | 249 } // namespace |
249 } // namespace file_manager | 250 } // namespace file_manager |
OLD | NEW |