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