| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <queue> | 5 #include <queue> |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "content/browser/device_orientation/data_fetcher.h" | 9 #include "content/browser/device_orientation/data_fetcher.h" |
| 10 #include "content/browser/device_orientation/orientation.h" | 10 #include "content/browser/device_orientation/orientation.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // Class for injecting test orientation data into the Provider. | 68 // Class for injecting test orientation data into the Provider. |
| 69 class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> { | 69 class MockOrientationFactory : public base::RefCounted<MockOrientationFactory> { |
| 70 public: | 70 public: |
| 71 MockOrientationFactory() { | 71 MockOrientationFactory() { |
| 72 EXPECT_FALSE(instance_); | 72 EXPECT_FALSE(instance_); |
| 73 instance_ = this; | 73 instance_ = this; |
| 74 } | 74 } |
| 75 | 75 |
| 76 ~MockOrientationFactory() { | |
| 77 instance_ = NULL; | |
| 78 } | |
| 79 | |
| 80 static DataFetcher* CreateDataFetcher() { | 76 static DataFetcher* CreateDataFetcher() { |
| 81 EXPECT_TRUE(instance_); | 77 EXPECT_TRUE(instance_); |
| 82 return new MockDataFetcher(instance_); | 78 return new MockDataFetcher(instance_); |
| 83 } | 79 } |
| 84 | 80 |
| 85 void SetOrientation(const Orientation& orientation) { | 81 void SetOrientation(const Orientation& orientation) { |
| 86 base::AutoLock auto_lock(lock_); | 82 base::AutoLock auto_lock(lock_); |
| 87 orientation_ = orientation; | 83 orientation_ = orientation; |
| 88 } | 84 } |
| 89 | 85 |
| 90 private: | 86 private: |
| 87 friend class base::RefCounted<MockOrientationFactory>; |
| 88 |
| 89 ~MockOrientationFactory() { |
| 90 instance_ = NULL; |
| 91 } |
| 92 |
| 91 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. | 93 // Owned by ProviderImpl. Holds a reference back to MockOrientationFactory. |
| 92 class MockDataFetcher : public DataFetcher { | 94 class MockDataFetcher : public DataFetcher { |
| 93 public: | 95 public: |
| 94 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) | 96 explicit MockDataFetcher(MockOrientationFactory* orientation_factory) |
| 95 : orientation_factory_(orientation_factory) { } | 97 : orientation_factory_(orientation_factory) { } |
| 96 | 98 |
| 97 // From DataFetcher. Called by the Provider. | 99 // From DataFetcher. Called by the Provider. |
| 98 virtual bool GetOrientation(Orientation* orientation) { | 100 virtual bool GetOrientation(Orientation* orientation) { |
| 99 base::AutoLock auto_lock(orientation_factory_->lock_); | 101 base::AutoLock auto_lock(orientation_factory_->lock_); |
| 100 *orientation = orientation_factory_->orientation_; | 102 *orientation = orientation_factory_->orientation_; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 checker_b->AddExpectation(third_orientation); | 387 checker_b->AddExpectation(third_orientation); |
| 386 MessageLoop::current()->Run(); | 388 MessageLoop::current()->Run(); |
| 387 | 389 |
| 388 provider_->RemoveObserver(checker_a.get()); | 390 provider_->RemoveObserver(checker_a.get()); |
| 389 provider_->RemoveObserver(checker_b.get()); | 391 provider_->RemoveObserver(checker_b.get()); |
| 390 } | 392 } |
| 391 | 393 |
| 392 } // namespace | 394 } // namespace |
| 393 | 395 |
| 394 } // namespace device_orientation | 396 } // namespace device_orientation |
| OLD | NEW |