| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_ | 6 #define EXTENSIONS_BROWSER_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 class HostResolver; |
| 14 class MockHostResolver; | 15 class MockHostResolver; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 // Used only for testing. Creates a MockHostResolver, respecting threading | 20 // Used only for testing. Creates a MockHostResolver, respecting threading |
| 20 // constraints. | 21 // constraints. |
| 21 class MockHostResolverCreator | 22 class MockHostResolverCreator |
| 22 : public base::RefCountedThreadSafe<MockHostResolverCreator> { | 23 : public base::RefCountedThreadSafe<MockHostResolverCreator> { |
| 23 public: | 24 public: |
| 24 static const std::string kHostname; | 25 static const std::string kHostname; |
| 25 static const std::string kAddress; | 26 static const std::string kAddress; |
| 26 | 27 |
| 27 MockHostResolverCreator(); | 28 MockHostResolverCreator(); |
| 28 | 29 |
| 29 net::MockHostResolver* CreateMockHostResolver(); | 30 net::HostResolver* CreateMockHostResolver(); |
| 30 void DeleteMockHostResolver(); | 31 void DeleteMockHostResolver(); |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 friend class base::RefCountedThreadSafe<MockHostResolverCreator>; | 34 friend class base::RefCountedThreadSafe<MockHostResolverCreator>; |
| 34 virtual ~MockHostResolverCreator(); | 35 virtual ~MockHostResolverCreator(); |
| 35 | 36 |
| 36 void CreateMockHostResolverOnIOThread(); | 37 void CreateMockHostResolverOnIOThread(); |
| 37 void DeleteMockHostResolverOnIOThread(); | 38 void DeleteMockHostResolverOnIOThread(); |
| 38 | 39 |
| 39 base::WaitableEvent resolver_event_; | 40 base::WaitableEvent resolver_event_; |
| 40 | 41 |
| 41 // The MockHostResolver asserts that it's used on the same thread on which | 42 // The MockHostResolver asserts that it's used on the same thread on which |
| 42 // it's created, which is actually a stronger rule than its real counterpart. | 43 // it's created, which is actually a stronger rule than its real counterpart. |
| 43 // But that's fine; it's good practice. | 44 // But that's fine; it's good practice. |
| 44 // | 45 // |
| 45 // Plain pointer because we have to manage lifetime manually. | 46 // Plain pointer because we have to manage lifetime manually. |
| 46 net::MockHostResolver* mock_host_resolver_; | 47 net::MockHostResolver* mock_host_resolver_; |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 } // namespace extensions | 50 } // namespace extensions |
| 50 | 51 |
| 51 #endif // CHROME_BROWSER_EXTENSIONS_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_ | 52 #endif // EXTENSIONS_BROWSER_API_DNS_MOCK_HOST_RESOLVER_CREATOR_H_ |
| OLD | NEW |