Chromium Code Reviews| 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_SHELL_INTEGRATION_H_ | 5 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| 6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ | 6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 class DefaultWebClientObserver { | 196 class DefaultWebClientObserver { |
| 197 public: | 197 public: |
| 198 virtual ~DefaultWebClientObserver() {} | 198 virtual ~DefaultWebClientObserver() {} |
| 199 // Updates the UI state to reflect the current default browser state. | 199 // Updates the UI state to reflect the current default browser state. |
| 200 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; | 200 virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
| 201 // Called to notify the UI of the immediate result of invoking | 201 // Called to notify the UI of the immediate result of invoking |
| 202 // SetAsDefault. | 202 // SetAsDefault. |
| 203 virtual void OnSetAsDefaultConcluded(bool succeeded) {} | 203 virtual void OnSetAsDefaultConcluded(bool succeeded) {} |
| 204 // Observer classes that return true to OwnedByWorker are automatically | |
| 205 // freed by the worker when they are no longer needed. False by default. | |
| 206 virtual bool IsOwnedByWorker(); | |
| 207 // An observer can permit or decline set-as-default operation if it | |
| 208 // requires triggering user interaction. By default not allowed. | |
| 209 virtual bool IsInteractiveSetDefaultPermitted(); | |
| 210 }; | 204 }; |
| 211 | 205 |
| 212 // Helper objects that handle checking if Chrome is the default browser | 206 // Helper objects that handle checking if Chrome is the default browser |
| 213 // or application for a url protocol on Windows and Linux, and also setting | 207 // or application for a url protocol on Windows and Linux, and also setting |
| 214 // it as the default. These operations are performed asynchronously on the | 208 // it as the default. These operations are performed asynchronously on the |
| 215 // file thread since registry access (on Windows) or the preference database | 209 // file thread since registry access (on Windows) or the preference database |
| 216 // (on Linux) are involved and this can be slow. | 210 // (on Linux) are involved and this can be slow. |
|
grt (UTC plus 2)
2016/02/03 15:39:56
please add something like:
"By default, the worker
Patrick Monette
2016/02/03 23:01:38
Done.
| |
| 217 class DefaultWebClientWorker | 211 class DefaultWebClientWorker |
| 218 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { | 212 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
| 219 public: | 213 public: |
| 220 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); | 214 // Constructor. The worker will post updates to |observer|. If |
| 215 // |delete_observer| is true, the worker owns the observer and it will be | |
| 216 // freed in the destructor. | |
| 217 DefaultWebClientWorker(DefaultWebClientObserver* observer, | |
| 218 bool delete_observer); | |
| 219 | |
| 220 // Controls whether the worker can use user interaction to set the default | |
| 221 // web client. If false, the set-as-default operation will fail on OS where | |
| 222 // it is required. | |
| 223 void SetInteractivePermitted(bool interactive_permitted); | |
|
grt (UTC plus 2)
2016/02/03 15:39:56
nit: this can be inlined as set_interactive_permit
Patrick Monette
2016/02/03 23:01:39
Done.
| |
| 221 | 224 |
| 222 // Checks to see if Chrome is the default web client application. The result | 225 // Checks to see if Chrome is the default web client application. The result |
| 223 // will be passed back to the observer via the SetDefaultWebClientUIState | 226 // will be passed back to the observer via the SetDefaultWebClientUIState |
| 224 // function. If there is no observer, this function does not do anything. | 227 // function. If there is no observer, this function does not do anything. |
| 225 void StartCheckIsDefault(); | 228 void StartCheckIsDefault(); |
| 226 | 229 |
| 227 // Sets Chrome as the default web client application. If there is an | 230 // Sets Chrome as the default web client application. If there is an |
| 228 // observer, once the operation has completed the new default will be | 231 // observer, once the operation has completed the new default will be |
| 229 // queried and the current status reported via SetDefaultWebClientUIState. | 232 // queried and the current status reported via SetDefaultWebClientUIState. |
| 230 void StartSetAsDefault(); | 233 void StartSetAsDefault(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 // is default process. | 277 // is default process. |
| 275 // It is safe to call this multiple times. Only the first call is processed | 278 // It is safe to call this multiple times. Only the first call is processed |
| 276 // after StartSetAsDefault() is invoked. | 279 // after StartSetAsDefault() is invoked. |
| 277 void OnSetAsDefaultAttemptComplete(AttemptResult result); | 280 void OnSetAsDefaultAttemptComplete(AttemptResult result); |
| 278 | 281 |
| 279 // Returns true if FinalizeSetAsDefault() will be called. | 282 // Returns true if FinalizeSetAsDefault() will be called. |
| 280 bool set_as_default_initialized() const { | 283 bool set_as_default_initialized() const { |
| 281 return set_as_default_initialized_; | 284 return set_as_default_initialized_; |
| 282 } | 285 } |
| 283 | 286 |
| 287 // When false, the operation to set as default will fail for interactive | |
| 288 // flows. | |
| 289 bool interactive_permitted_ = true; | |
| 290 | |
| 284 // Flag that indicates if the set-as-default operation is in progess to | 291 // Flag that indicates if the set-as-default operation is in progess to |
| 285 // prevent multiple notifications to the observer. | 292 // prevent multiple notifications to the observer. |
| 286 bool set_as_default_in_progress_ = false; | 293 bool set_as_default_in_progress_ = false; |
| 287 | 294 |
| 288 private: | 295 private: |
| 289 // Checks whether Chrome is the default web client. Always called on the | 296 // Checks whether Chrome is the default web client. Always called on the |
| 290 // FILE thread. Subclasses are responsible for calling | 297 // FILE thread. Subclasses are responsible for calling |
| 291 // OnCheckIsDefaultComplete() on the UI thread. | 298 // OnCheckIsDefaultComplete() on the UI thread. |
| 292 virtual void CheckIsDefault() = 0; | 299 virtual void CheckIsDefault() = 0; |
| 293 | 300 |
| 294 // Sets Chrome as the default web client. Always called on the FILE thread. | 301 // Sets Chrome as the default web client. Always called on the FILE thread. |
| 295 // |interactive_permitted| will make SetAsDefault() fail if it requires | 302 // Subclasses are responsible for calling OnSetAsDefaultAttemptComplete() on |
| 296 // interaction with the user. Subclasses are responsible for calling | 303 // the UI thread. |
| 297 // OnSetAsDefaultAttemptComplete() on the UI thread. | 304 virtual void SetAsDefault() = 0; |
| 298 virtual void SetAsDefault(bool interactive_permitted) = 0; | |
| 299 | 305 |
| 300 // Returns the prefix used for metrics to differentiate UMA metrics for | 306 // Returns the prefix used for metrics to differentiate UMA metrics for |
| 301 // setting the default browser and setting the default protocol client. | 307 // setting the default browser and setting the default protocol client. |
| 302 virtual const char* GetHistogramPrefix() = 0; | 308 virtual const char* GetHistogramPrefix() = 0; |
| 303 | 309 |
| 304 // Invoked on the UI thread prior to starting a set-as-default operation. | 310 // Invoked on the UI thread prior to starting a set-as-default operation. |
| 305 // Returns true if the initialization succeeded and a subsequent call to | 311 // Returns true if the initialization succeeded and a subsequent call to |
| 306 // FinalizeSetAsDefault() is required. | 312 // FinalizeSetAsDefault() is required. |
| 307 virtual bool InitializeSetAsDefault(); | 313 virtual bool InitializeSetAsDefault(); |
| 308 | 314 |
| 309 // Invoked on the UI thread following a set-as-default operation. | 315 // Invoked on the UI thread following a set-as-default operation. |
| 310 virtual void FinalizeSetAsDefault(); | 316 virtual void FinalizeSetAsDefault(); |
| 311 | 317 |
| 312 // Reports the result and duration for one set-as-default attempt. | 318 // Reports the result and duration for one set-as-default attempt. |
| 313 void ReportAttemptResult(AttemptResult result); | 319 void ReportAttemptResult(AttemptResult result); |
| 314 | 320 |
| 315 // Updates the UI in our associated view with the current default web | 321 // Updates the UI in our associated view with the current default web |
| 316 // client state. | 322 // client state. |
| 317 void UpdateUI(DefaultWebClientState state); | 323 void UpdateUI(DefaultWebClientState state); |
| 318 | 324 |
| 319 // Returns true if the duration of an attempt to set the default web client | 325 // Returns true if the duration of an attempt to set the default web client |
| 320 // should be reported to UMA for |result|. | 326 // should be reported to UMA for |result|. |
| 321 static bool ShouldReportDurationForResult(AttemptResult result); | 327 static bool ShouldReportDurationForResult(AttemptResult result); |
| 322 | 328 |
| 323 // Returns a string based on |result|. This is used for UMA reports. | 329 // Returns a string based on |result|. This is used for UMA reports. |
| 324 static const char* AttemptResultToString(AttemptResult result); | 330 static const char* AttemptResultToString(AttemptResult result); |
| 325 | 331 |
| 326 DefaultWebClientObserver* observer_; | 332 DefaultWebClientObserver* observer_; |
| 327 | 333 |
| 334 // Indicates if the the observer will be automatically freed by the worker. | |
| 335 bool delete_observer_; | |
| 336 | |
| 328 // Flag that indicates the return value of InitializeSetAsDefault(). If | 337 // Flag that indicates the return value of InitializeSetAsDefault(). If |
| 329 // true, FinalizeSetAsDefault() will be called to clear what was | 338 // true, FinalizeSetAsDefault() will be called to clear what was |
| 330 // initialized. | 339 // initialized. |
| 331 bool set_as_default_initialized_ = false; | 340 bool set_as_default_initialized_ = false; |
| 332 | 341 |
| 333 // Records the time it takes to set the default browser. | 342 // Records the time it takes to set the default browser. |
| 334 base::TimeTicks start_time_; | 343 base::TimeTicks start_time_; |
| 335 | 344 |
| 336 // Wait until Chrome has been confirmed as the default browser before | 345 // Wait until Chrome has been confirmed as the default browser before |
| 337 // reporting a successful attempt. | 346 // reporting a successful attempt. |
| 338 bool check_default_should_report_success_ = false; | 347 bool check_default_should_report_success_ = false; |
| 339 | 348 |
| 340 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 349 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| 341 }; | 350 }; |
| 342 | 351 |
| 343 // Worker for checking and setting the default browser. | 352 // Worker for checking and setting the default browser. |
| 344 class DefaultBrowserWorker : public DefaultWebClientWorker { | 353 class DefaultBrowserWorker : public DefaultWebClientWorker { |
| 345 public: | 354 public: |
| 346 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 355 // Constructor. The worker will post updates to |observer|. If |
| 356 // |delete_observer| is true, the worker owns the observer and it will be | |
| 357 // freed in the destructor. | |
| 358 DefaultBrowserWorker(DefaultWebClientObserver* observer, | |
| 359 bool delete_observer); | |
| 347 | 360 |
| 348 private: | 361 private: |
| 349 ~DefaultBrowserWorker() override; | 362 ~DefaultBrowserWorker() override; |
| 350 | 363 |
| 351 // Check if Chrome is the default browser. | 364 // Check if Chrome is the default browser. |
| 352 void CheckIsDefault() override; | 365 void CheckIsDefault() override; |
| 353 | 366 |
| 354 // Set Chrome as the default browser. | 367 // Set Chrome as the default browser. |
| 355 void SetAsDefault(bool interactive_permitted) override; | 368 void SetAsDefault() override; |
| 356 | 369 |
| 357 // Returns the histogram prefix for DefaultBrowserWorker. | 370 // Returns the histogram prefix for DefaultBrowserWorker. |
| 358 const char* GetHistogramPrefix() override; | 371 const char* GetHistogramPrefix() override; |
| 359 | 372 |
| 360 #if defined(OS_WIN) | 373 #if defined(OS_WIN) |
| 361 // On Windows 10+, adds the default browser callback and starts the timer | 374 // On Windows 10+, adds the default browser callback and starts the timer |
| 362 // that determines if the operation was successful or not. | 375 // that determines if the operation was successful or not. |
| 363 bool InitializeSetAsDefault() override; | 376 bool InitializeSetAsDefault() override; |
| 364 | 377 |
| 365 // On Windows 10+, removes the default browser callback and stops the timer. | 378 // On Windows 10+, removes the default browser callback and stops the timer. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 376 | 389 |
| 377 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 390 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 378 }; | 391 }; |
| 379 | 392 |
| 380 // Worker for checking and setting the default client application | 393 // Worker for checking and setting the default client application |
| 381 // for a given protocol. A different worker instance is needed for each | 394 // for a given protocol. A different worker instance is needed for each |
| 382 // protocol you are interested in, so to check or set the default for | 395 // protocol you are interested in, so to check or set the default for |
| 383 // multiple protocols you should use multiple worker objects. | 396 // multiple protocols you should use multiple worker objects. |
| 384 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 397 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| 385 public: | 398 public: |
| 399 // Constructor. The worker will post updates to |observer|. If | |
| 400 // |delete_observer| is true, the worker owns the observer and it will be | |
| 401 // freed in the destructor. | |
| 386 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 402 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| 387 const std::string& protocol); | 403 const std::string& protocol, |
| 404 bool delete_observer); | |
| 388 | 405 |
| 389 const std::string& protocol() const { return protocol_; } | 406 const std::string& protocol() const { return protocol_; } |
| 390 | 407 |
| 391 protected: | 408 protected: |
| 392 ~DefaultProtocolClientWorker() override; | 409 ~DefaultProtocolClientWorker() override; |
| 393 | 410 |
| 394 private: | 411 private: |
| 395 // Check is Chrome is the default handler for this protocol. | 412 // Check is Chrome is the default handler for this protocol. |
| 396 void CheckIsDefault() override; | 413 void CheckIsDefault() override; |
| 397 | 414 |
| 398 // Set Chrome as the default handler for this protocol. | 415 // Set Chrome as the default handler for this protocol. |
| 399 void SetAsDefault(bool interactive_permitted) override; | 416 void SetAsDefault() override; |
| 400 | 417 |
| 401 // Returns the histogram prefix for DefaultProtocolClientWorker. | 418 // Returns the histogram prefix for DefaultProtocolClientWorker. |
| 402 const char* GetHistogramPrefix() override; | 419 const char* GetHistogramPrefix() override; |
| 403 | 420 |
| 404 std::string protocol_; | 421 std::string protocol_; |
| 405 | 422 |
| 406 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 423 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| 407 }; | 424 }; |
| 408 }; | 425 }; |
| 409 | 426 |
| 410 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 427 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| OLD | NEW |