Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_service_launcher.h" | 17 #include "chrome/browser/chromeos/arc/arc_service_launcher.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 18 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 // Set unmanaged auth token for other Android unmanaged accounts. | 58 // Set unmanaged auth token for other Android unmanaged accounts. |
| 58 constexpr char kUnmanagedAuthToken[] = "unmanaged-auth-token"; | 59 constexpr char kUnmanagedAuthToken[] = "unmanaged-auth-token"; |
| 59 constexpr char kWellKnownConsumerName[] = "test@gmail.com"; | 60 constexpr char kWellKnownConsumerName[] = "test@gmail.com"; |
| 60 constexpr char kFakeUserName[] = "test@example.com"; | 61 constexpr char kFakeUserName[] = "test@example.com"; |
| 61 constexpr char kFakeGaiaId[] = "1234567890"; | 62 constexpr char kFakeGaiaId[] = "1234567890"; |
| 62 | 63 |
| 63 } // namespace | 64 } // namespace |
| 64 | 65 |
| 65 namespace arc { | 66 namespace arc { |
| 66 | 67 |
| 67 // Observer of ARC bridge shutdown. | 68 // Waits for the "arc.enabled" preference change. |
| 68 class ArcSessionManagerShutdownObserver : public ArcSessionManager::Observer { | 69 class ArcPlayStoreEnabledChangedWaiter : public ArcSessionManager::Observer { |
| 69 public: | 70 public: |
| 70 ArcSessionManagerShutdownObserver() { | 71 ArcPlayStoreEnabledChangedWaiter() { |
| 71 ArcSessionManager::Get()->AddObserver(this); | 72 ArcSessionManager::Get()->AddObserver(this); |
| 72 } | 73 } |
| 73 | 74 |
| 74 ~ArcSessionManagerShutdownObserver() override { | 75 ~ArcPlayStoreEnabledChangedWaiter() override { |
| 75 ArcSessionManager::Get()->RemoveObserver(this); | 76 ArcSessionManager::Get()->RemoveObserver(this); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void Wait() { | 79 void Wait() { |
| 79 run_loop_.reset(new base::RunLoop); | 80 base::RunLoop run_loop; |
| 80 run_loop_->Run(); | 81 base::AutoReset<base::RunLoop*> reset(&run_loop_, &run_loop); |
|
Luis Héctor Chávez
2017/02/15 18:44:50
nice, this looks _much_ cleaner :)
hidehiko
2017/02/15 18:51:53
Thanks :-).
| |
| 81 run_loop_.reset(); | 82 run_loop.Run(); |
| 82 } | |
| 83 | |
| 84 // ArcSessionManager::Observer: | |
| 85 void OnArcBridgeShutdown() override { | |
| 86 if (!run_loop_) | |
| 87 return; | |
| 88 run_loop_->Quit(); | |
| 89 } | 83 } |
| 90 | 84 |
| 91 private: | 85 private: |
| 92 std::unique_ptr<base::RunLoop> run_loop_; | 86 // ArcSessionManager::Observer override: |
| 87 void OnArcPlayStoreEnabledChanged(bool enabled) override { | |
| 88 if (run_loop_) | |
|
Luis Héctor Chávez
2017/02/15 18:44:50
nit:
if (!enabled) {
DCHECK(run_loop_);
run_l
hidehiko
2017/02/15 18:51:53
It changes the semantics (from the brief document
Luis Héctor Chávez
2017/02/15 19:09:44
So previously the semantics for this class was to
hidehiko
2017/02/15 19:52:43
Ok, thank you for detailed explanation.
Done.
| |
| 89 run_loop_->Quit(); | |
| 90 } | |
| 93 | 91 |
| 94 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerShutdownObserver); | 92 base::RunLoop* run_loop_ = nullptr; |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(ArcPlayStoreEnabledChangedWaiter); | |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 class ArcSessionManagerTest : public InProcessBrowserTest { | 97 class ArcSessionManagerTest : public InProcessBrowserTest { |
| 98 protected: | 98 protected: |
| 99 ArcSessionManagerTest() {} | 99 ArcSessionManagerTest() {} |
| 100 | 100 |
| 101 // InProcessBrowserTest: | 101 // InProcessBrowserTest: |
| 102 ~ArcSessionManagerTest() override {} | 102 ~ArcSessionManagerTest() override {} |
| 103 | 103 |
| 104 void SetUpCommandLine(base::CommandLine* command_line) override { | 104 void SetUpCommandLine(base::CommandLine* command_line) override { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 | 220 |
| 221 EnableArc(); | 221 EnableArc(); |
| 222 ASSERT_EQ(ArcSessionManager::State::ACTIVE, | 222 ASSERT_EQ(ArcSessionManager::State::ACTIVE, |
| 223 ArcSessionManager::Get()->state()); | 223 ArcSessionManager::Get()->state()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { | 226 IN_PROC_BROWSER_TEST_F(ArcSessionManagerTest, ManagedAndroidAccount) { |
| 227 EnableArc(); | 227 EnableArc(); |
| 228 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 228 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
| 229 base::Time::Max()); | 229 base::Time::Max()); |
| 230 ArcSessionManagerShutdownObserver().Wait(); | 230 ArcPlayStoreEnabledChangedWaiter().Wait(); |
| 231 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, | 231 ASSERT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR, |
| 232 ArcSessionManager::Get()->state()); | 232 ArcSessionManager::Get()->state()); |
| 233 ArcDataRemovedWaiter().Wait(); | 233 ArcDataRemovedWaiter().Wait(); |
| 234 ASSERT_EQ(ArcSessionManager::State::STOPPED, | 234 ASSERT_EQ(ArcSessionManager::State::STOPPED, |
| 235 ArcSessionManager::Get()->state()); | 235 ArcSessionManager::Get()->state()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 } // namespace arc | 238 } // namespace arc |
| OLD | NEW |