blob: e2372bc1fb1211fc7b11676d1578b221558ca2df (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/test/testing_application_context.h"
#include "base/logging.h"
#include "base/time/default_clock.h"
#include "base/time/default_tick_clock.h"
#include "components/network_time/network_time_tracker.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
TestingApplicationContext::TestingApplicationContext()
: application_locale_("en"),
local_state_(nullptr),
chrome_browser_state_manager_(nullptr),
was_last_shutdown_clean_(false) {
DCHECK(!GetApplicationContext());
SetApplicationContext(this);
}
TestingApplicationContext::~TestingApplicationContext() {
DCHECK_EQ(this, GetApplicationContext());
DCHECK(!local_state_);
SetApplicationContext(nullptr);
}
// static
TestingApplicationContext* TestingApplicationContext::GetGlobal() {
return static_cast<TestingApplicationContext*>(GetApplicationContext());
}
void TestingApplicationContext::SetLocalState(PrefService* local_state) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!local_state) {
// The local state is owned outside of TestingApplicationContext, but
// some of the members of TestingApplicationContext hold references to it.
// Given our test infrastructure which tears down individual tests before
// freeing the TestingApplicationContext, there's no good way to make the
// local state outlive these dependencies. As a workaround, whenever
// local state is cleared (assumedly as part of exiting the test) any
// components owned by TestingApplicationContext that depends on the local
// state are also freed.
network_time_tracker_.reset();
}
local_state_ = local_state;
}
void TestingApplicationContext::SetLastShutdownClean(bool clean) {
was_last_shutdown_clean_ = clean;
}
void TestingApplicationContext::SetChromeBrowserStateManager(
ios::ChromeBrowserStateManager* manager) {
DCHECK(thread_checker_.CalledOnValidThread());
chrome_browser_state_manager_ = manager;
}
void TestingApplicationContext::OnAppEnterForeground() {
DCHECK(thread_checker_.CalledOnValidThread());
}
void TestingApplicationContext::OnAppEnterBackground() {
DCHECK(thread_checker_.CalledOnValidThread());
}
bool TestingApplicationContext::WasLastShutdownClean() {
DCHECK(thread_checker_.CalledOnValidThread());
return was_last_shutdown_clean_;
}
PrefService* TestingApplicationContext::GetLocalState() {
DCHECK(thread_checker_.CalledOnValidThread());
return local_state_;
}
net::URLRequestContextGetter*
TestingApplicationContext::GetSystemURLRequestContext() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
const std::string& TestingApplicationContext::GetApplicationLocale() {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!application_locale_.empty());
return application_locale_;
}
ios::ChromeBrowserStateManager*
TestingApplicationContext::GetChromeBrowserStateManager() {
DCHECK(thread_checker_.CalledOnValidThread());
return chrome_browser_state_manager_;
}
metrics_services_manager::MetricsServicesManager*
TestingApplicationContext::GetMetricsServicesManager() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
metrics::MetricsService* TestingApplicationContext::GetMetricsService() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
variations::VariationsService*
TestingApplicationContext::GetVariationsService() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
rappor::RapporService* TestingApplicationContext::GetRapporService() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
net_log::ChromeNetLog* TestingApplicationContext::GetNetLog() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
network_time::NetworkTimeTracker*
TestingApplicationContext::GetNetworkTimeTracker() {
DCHECK(thread_checker_.CalledOnValidThread());
if (!network_time_tracker_) {
DCHECK(local_state_);
network_time_tracker_.reset(new network_time::NetworkTimeTracker(
make_scoped_ptr(new base::DefaultClock),
make_scoped_ptr(new base::DefaultTickClock), local_state_));
}
return network_time_tracker_.get();
}
IOSChromeIOThread* TestingApplicationContext::GetIOSChromeIOThread() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
gcm::GCMDriver* TestingApplicationContext::GetGCMDriver() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
web_resource::PromoResourceService*
TestingApplicationContext::GetPromoResourceService() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
component_updater::ComponentUpdateService*
TestingApplicationContext::GetComponentUpdateService() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
CRLSetFetcher* TestingApplicationContext::GetCRLSetFetcher() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
safe_browsing::SafeBrowsingService*
TestingApplicationContext::GetSafeBrowsingService() {
DCHECK(thread_checker_.CalledOnValidThread());
return nullptr;
}
|