Chromium Code Reviews| 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/extensions/api/file_system/file_system_api.h" | 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 class ScopedAddListenerObserver : public EventRouter::Observer { | 73 class ScopedAddListenerObserver : public EventRouter::Observer { |
| 74 public: | 74 public: |
| 75 ScopedAddListenerObserver(Profile* profile, | 75 ScopedAddListenerObserver(Profile* profile, |
| 76 const std::string& event_name, | 76 const std::string& event_name, |
| 77 const std::string& extension_id, | 77 const std::string& extension_id, |
| 78 const base::Closure& callback) | 78 const base::Closure& callback) |
| 79 : extension_id_(extension_id), | 79 : extension_id_(extension_id), |
| 80 callback_(callback), | 80 callback_(callback), |
| 81 event_router_(EventRouter::EventRouter::Get(profile)) { | 81 event_router_(EventRouter::EventRouter::Get(profile)) { |
| 82 DCHECK(profile); | 82 DCHECK(profile); |
| 83 DCHECK(event_router_); | |
| 84 event_router_->RegisterObserver(this, event_name); | 83 event_router_->RegisterObserver(this, event_name); |
| 85 } | 84 } |
| 86 | 85 |
| 87 ~ScopedAddListenerObserver() { event_router_->UnregisterObserver(this); } | 86 ~ScopedAddListenerObserver() override { |
| 87 event_router_->UnregisterObserver(this); | |
| 88 } | |
| 88 | 89 |
| 89 // EventRouter::Observer overrides. | 90 // EventRouter::Observer overrides. |
| 90 void OnListenerAdded(const EventListenerInfo& details) override { | 91 void OnListenerAdded(const EventListenerInfo& details) override { |
| 91 // Call the callback only once, as the listener may be added multiple times. | 92 // Call the callback only once, as the listener may be added multiple times. |
| 92 if (details.extension_id == extension_id_ && !callback_.is_null()) { | 93 if (details.extension_id != extension_id_ || !callback_) |
| 93 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_); | 94 return; |
| 94 callback_ = base::Closure(); | 95 |
| 95 } | 96 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback_); |
|
Devlin
2017/05/20 00:49:15
nit: PostTask(FROM_HERE, base::ResetAndReturn(&cal
Lei Zhang
2017/05/20 01:04:14
Done. I missed the memo on that one.
| |
| 97 callback_.Reset(); | |
| 96 } | 98 } |
| 97 | 99 |
| 98 private: | 100 private: |
| 99 const std::string extension_id_; | 101 const std::string extension_id_; |
| 100 base::Closure callback_; | 102 base::Closure callback_; |
| 101 EventRouter* const event_router_; | 103 EventRouter* const event_router_; |
| 102 | 104 |
| 103 DISALLOW_COPY_AND_ASSIGN(ScopedAddListenerObserver); | 105 DISALLOW_COPY_AND_ASSIGN(ScopedAddListenerObserver); |
| 104 }; | 106 }; |
| 105 | 107 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 profile(), extensions::api::file_system::OnVolumeListChanged::kEventName, | 489 profile(), extensions::api::file_system::OnVolumeListChanged::kEventName, |
| 488 kTestingExtensionId, | 490 kTestingExtensionId, |
| 489 base::Bind(&FileSystemApiTestForRequestFileSystem::MountFakeVolume, | 491 base::Bind(&FileSystemApiTestForRequestFileSystem::MountFakeVolume, |
| 490 base::Unretained(this))); | 492 base::Unretained(this))); |
| 491 | 493 |
| 492 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/on_volume_list_changed")) | 494 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/on_volume_list_changed")) |
| 493 << message_; | 495 << message_; |
| 494 } | 496 } |
| 495 | 497 |
| 496 } // namespace extensions | 498 } // namespace extensions |
| OLD | NEW |