OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_frame/ready_mode/ready_mode.h" | 5 #include "chrome_frame/ready_mode/ready_mode.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <shlguid.h> | 8 #include <shlguid.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/linked_ptr.h" | 12 #include "base/linked_ptr.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/weak_ptr.h" | 14 #include "base/weak_ptr.h" |
15 #include "base/win/scoped_bstr.h" | 15 #include "base/win/scoped_bstr.h" |
16 #include "base/win/scoped_comptr.h" | 16 #include "base/win/scoped_comptr.h" |
17 #include "base/win/win_util.h" | 17 #include "base/win/win_util.h" |
| 18 #include "chrome/installer/util/browser_distribution.h" |
18 #include "net/base/registry_controlled_domain.h" | 19 #include "net/base/registry_controlled_domain.h" |
19 #include "chrome/installer/util/package_properties.h" | |
20 #include "chrome_frame/infobars/infobar_manager.h" | 20 #include "chrome_frame/infobars/infobar_manager.h" |
21 #include "chrome_frame/ready_mode/internal/ready_mode_web_browser_adapter.h" | 21 #include "chrome_frame/ready_mode/internal/ready_mode_web_browser_adapter.h" |
22 #include "chrome_frame/ready_mode/internal/ready_prompt_content.h" | 22 #include "chrome_frame/ready_mode/internal/ready_prompt_content.h" |
23 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" | 23 #include "chrome_frame/ready_mode/internal/registry_ready_mode_state.h" |
24 #include "chrome_frame/utils.h" | 24 #include "chrome_frame/utils.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Temporarily disable Ready Mode for 36 hours when the user so indicates. | 28 // Temporarily disable Ready Mode for 36 hours when the user so indicates. |
29 const int kTemporaryDeclineDurationMinutes = 60 * 36; | 29 const int kTemporaryDeclineDurationMinutes = 60 * 36; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 void BrowserObserver::ShowPrompt() { | 185 void BrowserObserver::ShowPrompt() { |
186 // This pointer is self-managed and not guaranteed to survive handling of | 186 // This pointer is self-managed and not guaranteed to survive handling of |
187 // Windows events. | 187 // Windows events. |
188 InfobarManager* infobar_manager = GetInfobarManager(); | 188 InfobarManager* infobar_manager = GetInfobarManager(); |
189 | 189 |
190 if (infobar_manager) { | 190 if (infobar_manager) { |
191 // Owned by ready_mode_state | 191 // Owned by ready_mode_state |
192 scoped_ptr<RegistryReadyModeState::Observer> ready_mode_state_observer( | 192 scoped_ptr<RegistryReadyModeState::Observer> ready_mode_state_observer( |
193 new StateObserver(weak_ptr_factory_.GetWeakPtr())); | 193 new StateObserver(weak_ptr_factory_.GetWeakPtr())); |
194 | 194 |
195 installer::ActivePackageProperties package_properties; | 195 BrowserDistribution* dist = |
| 196 BrowserDistribution::GetSpecificDistribution( |
| 197 BrowserDistribution::CHROME_BINARIES); |
196 | 198 |
197 // Owned by infobar_content | 199 // Owned by infobar_content |
198 scoped_ptr<ReadyModeState> ready_mode_state(new RegistryReadyModeState( | 200 scoped_ptr<ReadyModeState> ready_mode_state(new RegistryReadyModeState( |
199 package_properties.GetStateKey(), | 201 dist->GetStateKey(), |
200 base::TimeDelta::FromMinutes(kTemporaryDeclineDurationMinutes), | 202 base::TimeDelta::FromMinutes(kTemporaryDeclineDurationMinutes), |
201 ready_mode_state_observer.release())); | 203 ready_mode_state_observer.release())); |
202 | 204 |
203 // Owned by infobar_manager | 205 // Owned by infobar_manager |
204 scoped_ptr<InfobarContent> infobar_content( | 206 scoped_ptr<InfobarContent> infobar_content( |
205 new ReadyPromptContent(ready_mode_state.release())); | 207 new ReadyPromptContent(ready_mode_state.release())); |
206 | 208 |
207 infobar_manager->Show(infobar_content.release(), TOP_INFOBAR); | 209 infobar_manager->Show(infobar_content.release(), TOP_INFOBAR); |
208 } | 210 } |
209 } | 211 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 namespace ready_mode { | 324 namespace ready_mode { |
323 | 325 |
324 // Determines the current Ready Mode state. If it is active, attempts to set up | 326 // Determines the current Ready Mode state. If it is active, attempts to set up |
325 // prompting. If we cannot set up prompting, attempts to temporarily disable | 327 // prompting. If we cannot set up prompting, attempts to temporarily disable |
326 // Ready Mode. In the end, if Ready Mode is disabled, pass that information on | 328 // Ready Mode. In the end, if Ready Mode is disabled, pass that information on |
327 // to the Delegate, so that it may disabled Chrome Frame functionality. | 329 // to the Delegate, so that it may disabled Chrome Frame functionality. |
328 void Configure(Delegate* chrome_frame, IWebBrowser2* web_browser) { | 330 void Configure(Delegate* chrome_frame, IWebBrowser2* web_browser) { |
329 // Take ownership of the delegate | 331 // Take ownership of the delegate |
330 linked_ptr<Delegate> delegate(chrome_frame); | 332 linked_ptr<Delegate> delegate(chrome_frame); |
331 chrome_frame = NULL; | 333 chrome_frame = NULL; |
| 334 BrowserDistribution* dist = |
| 335 BrowserDistribution::GetSpecificDistribution( |
| 336 BrowserDistribution::CHROME_BINARIES); |
332 | 337 |
333 RegistryReadyModeState ready_mode_state( | 338 RegistryReadyModeState ready_mode_state( |
334 installer::ActivePackageProperties().GetStateKey(), | 339 dist->GetStateKey(), |
335 base::TimeDelta::FromMinutes(kTemporaryDeclineDurationMinutes), | 340 base::TimeDelta::FromMinutes(kTemporaryDeclineDurationMinutes), |
336 NULL); // NULL => no observer required | 341 NULL); // NULL => no observer required |
337 | 342 |
338 ReadyModeStatus status = ready_mode_state.GetStatus(); | 343 ReadyModeStatus status = ready_mode_state.GetStatus(); |
339 | 344 |
340 // If the user temporarily declined Chrome Frame, but the timeout has elapsed, | 345 // If the user temporarily declined Chrome Frame, but the timeout has elapsed, |
341 // attempt to revert to active Ready Mode state. | 346 // attempt to revert to active Ready Mode state. |
342 if (status == READY_MODE_TEMPORARY_DECLINE_EXPIRED) { | 347 if (status == READY_MODE_TEMPORARY_DECLINE_EXPIRED) { |
343 ready_mode_state.ExpireTemporaryDecline(); | 348 ready_mode_state.ExpireTemporaryDecline(); |
344 status = ready_mode_state.GetStatus(); | 349 status = ready_mode_state.GetStatus(); |
345 } | 350 } |
346 | 351 |
347 // If Ready Mode is active, attempt to set up prompting. | 352 // If Ready Mode is active, attempt to set up prompting. |
348 if (status == READY_MODE_ACTIVE) { | 353 if (status == READY_MODE_ACTIVE) { |
349 if (!InstallPrompts(delegate, web_browser)) { | 354 if (!InstallPrompts(delegate, web_browser)) { |
350 // Failed to set up prompting. Turn off Ready Mode for now. | 355 // Failed to set up prompting. Turn off Ready Mode for now. |
351 ready_mode_state.TemporarilyDeclineChromeFrame(); | 356 ready_mode_state.TemporarilyDeclineChromeFrame(); |
352 status = ready_mode_state.GetStatus(); | 357 status = ready_mode_state.GetStatus(); |
353 } | 358 } |
354 } | 359 } |
355 | 360 |
356 // Depending on the state we finally end up in, tell our Delegate to disable | 361 // Depending on the state we finally end up in, tell our Delegate to disable |
357 // Chrome Frame functionality. | 362 // Chrome Frame functionality. |
358 if (ShouldDisableChromeFrame(status)) | 363 if (ShouldDisableChromeFrame(status)) |
359 delegate->DisableChromeFrame(); | 364 delegate->DisableChromeFrame(); |
360 } | 365 } |
361 | 366 |
362 } // namespace ready_mode | 367 } // namespace ready_mode |
OLD | NEW |