Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/shell_integration.h

Issue 1657933003: Fixes the interactive default browser UX for policy setting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
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 DefaultWebClientWorker(DefaultWebClientObserver* observer,
grt (UTC plus 2) 2016/02/02 17:28:22 please add a doc comment for this function (and th
Patrick Monette 2016/02/02 22:24:15 Done.
215 bool delete_observer,
216 bool interactive_permitted);
221 217
222 // Checks to see if Chrome is the default web client application. The result 218 // Checks to see if Chrome is the default web client application. The result
223 // will be passed back to the observer via the SetDefaultWebClientUIState 219 // will be passed back to the observer via the SetDefaultWebClientUIState
224 // function. If there is no observer, this function does not do anything. 220 // function. If there is no observer, this function does not do anything.
225 void StartCheckIsDefault(); 221 void StartCheckIsDefault();
226 222
227 // Sets Chrome as the default web client application. If there is an 223 // Sets Chrome as the default web client application. If there is an
228 // observer, once the operation has completed the new default will be 224 // observer, once the operation has completed the new default will be
229 // queried and the current status reported via SetDefaultWebClientUIState. 225 // queried and the current status reported via SetDefaultWebClientUIState.
230 void StartSetAsDefault(); 226 void StartSetAsDefault();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // is default process. 270 // is default process.
275 // It is safe to call this multiple times. Only the first call is processed 271 // It is safe to call this multiple times. Only the first call is processed
276 // after StartSetAsDefault() is invoked. 272 // after StartSetAsDefault() is invoked.
277 void OnSetAsDefaultAttemptComplete(AttemptResult result); 273 void OnSetAsDefaultAttemptComplete(AttemptResult result);
278 274
279 // Returns true if FinalizeSetAsDefault() will be called. 275 // Returns true if FinalizeSetAsDefault() will be called.
280 bool set_as_default_initialized() const { 276 bool set_as_default_initialized() const {
281 return set_as_default_initialized_; 277 return set_as_default_initialized_;
282 } 278 }
283 279
280 // When false, the operation to set as default will fail for interactive
281 // flows.
282 bool interactive_permitted_;
283
284 // Flag that indicates if the set-as-default operation is in progess to 284 // Flag that indicates if the set-as-default operation is in progess to
285 // prevent multiple notifications to the observer. 285 // prevent multiple notifications to the observer.
286 bool set_as_default_in_progress_ = false; 286 bool set_as_default_in_progress_ = false;
287 287
288 private: 288 private:
289 // Checks whether Chrome is the default web client. Always called on the 289 // Checks whether Chrome is the default web client. Always called on the
290 // FILE thread. Subclasses are responsible for calling 290 // FILE thread. Subclasses are responsible for calling
291 // OnCheckIsDefaultComplete() on the UI thread. 291 // OnCheckIsDefaultComplete() on the UI thread.
292 virtual void CheckIsDefault() = 0; 292 virtual void CheckIsDefault() = 0;
293 293
294 // Sets Chrome as the default web client. Always called on the FILE thread. 294 // Sets Chrome as the default web client. Always called on the FILE thread.
295 // |interactive_permitted| will make SetAsDefault() fail if it requires 295 // Subclasses are responsible for calling OnSetAsDefaultAttemptComplete() on
296 // interaction with the user. Subclasses are responsible for calling 296 // the UI thread.
297 // OnSetAsDefaultAttemptComplete() on the UI thread. 297 virtual void SetAsDefault() = 0;
298 virtual void SetAsDefault(bool interactive_permitted) = 0;
299 298
300 // Returns the prefix used for metrics to differentiate UMA metrics for 299 // Returns the prefix used for metrics to differentiate UMA metrics for
301 // setting the default browser and setting the default protocol client. 300 // setting the default browser and setting the default protocol client.
302 virtual const char* GetHistogramPrefix() = 0; 301 virtual const char* GetHistogramPrefix() = 0;
303 302
304 // Invoked on the UI thread prior to starting a set-as-default operation. 303 // 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 304 // Returns true if the initialization succeeded and a subsequent call to
306 // FinalizeSetAsDefault() is required. 305 // FinalizeSetAsDefault() is required.
307 virtual bool InitializeSetAsDefault(); 306 virtual bool InitializeSetAsDefault();
308 307
309 // Invoked on the UI thread following a set-as-default operation. 308 // Invoked on the UI thread following a set-as-default operation.
310 virtual void FinalizeSetAsDefault(); 309 virtual void FinalizeSetAsDefault();
311 310
312 // Reports the result and duration for one set-as-default attempt. 311 // Reports the result and duration for one set-as-default attempt.
313 void ReportAttemptResult(AttemptResult result); 312 void ReportAttemptResult(AttemptResult result);
314 313
315 // Updates the UI in our associated view with the current default web 314 // Updates the UI in our associated view with the current default web
316 // client state. 315 // client state.
317 void UpdateUI(DefaultWebClientState state); 316 void UpdateUI(DefaultWebClientState state);
318 317
319 // Returns true if the duration of an attempt to set the default web client 318 // Returns true if the duration of an attempt to set the default web client
320 // should be reported to UMA for |result|. 319 // should be reported to UMA for |result|.
321 static bool ShouldReportDurationForResult(AttemptResult result); 320 static bool ShouldReportDurationForResult(AttemptResult result);
322 321
323 // Returns a string based on |result|. This is used for UMA reports. 322 // Returns a string based on |result|. This is used for UMA reports.
324 static const char* AttemptResultToString(AttemptResult result); 323 static const char* AttemptResultToString(AttemptResult result);
325 324
326 DefaultWebClientObserver* observer_; 325 DefaultWebClientObserver* observer_;
327 326
327 // Indicates if the the observer will be automatically freed by the worker.
328 bool delete_observer_;
329
328 // Flag that indicates the return value of InitializeSetAsDefault(). If 330 // Flag that indicates the return value of InitializeSetAsDefault(). If
329 // true, FinalizeSetAsDefault() will be called to clear what was 331 // true, FinalizeSetAsDefault() will be called to clear what was
330 // initialized. 332 // initialized.
331 bool set_as_default_initialized_ = false; 333 bool set_as_default_initialized_ = false;
332 334
333 // Records the time it takes to set the default browser. 335 // Records the time it takes to set the default browser.
334 base::TimeTicks start_time_; 336 base::TimeTicks start_time_;
335 337
336 // Wait until Chrome has been confirmed as the default browser before 338 // Wait until Chrome has been confirmed as the default browser before
337 // reporting a successful attempt. 339 // reporting a successful attempt.
338 bool check_default_should_report_success_ = false; 340 bool check_default_should_report_success_ = false;
339 341
340 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); 342 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker);
341 }; 343 };
342 344
343 // Worker for checking and setting the default browser. 345 // Worker for checking and setting the default browser.
344 class DefaultBrowserWorker : public DefaultWebClientWorker { 346 class DefaultBrowserWorker : public DefaultWebClientWorker {
345 public: 347 public:
346 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); 348 DefaultBrowserWorker(DefaultWebClientObserver* observer,
349 bool delete_observer,
350 bool interactive_permitted);
347 351
348 private: 352 private:
349 ~DefaultBrowserWorker() override; 353 ~DefaultBrowserWorker() override;
350 354
351 // Check if Chrome is the default browser. 355 // Check if Chrome is the default browser.
352 void CheckIsDefault() override; 356 void CheckIsDefault() override;
353 357
354 // Set Chrome as the default browser. 358 // Set Chrome as the default browser.
355 void SetAsDefault(bool interactive_permitted) override; 359 void SetAsDefault() override;
356 360
357 // Returns the histogram prefix for DefaultBrowserWorker. 361 // Returns the histogram prefix for DefaultBrowserWorker.
358 const char* GetHistogramPrefix() override; 362 const char* GetHistogramPrefix() override;
359 363
360 #if defined(OS_WIN) 364 #if defined(OS_WIN)
361 // On Windows 10+, adds the default browser callback and starts the timer 365 // On Windows 10+, adds the default browser callback and starts the timer
362 // that determines if the operation was successful or not. 366 // that determines if the operation was successful or not.
363 bool InitializeSetAsDefault() override; 367 bool InitializeSetAsDefault() override;
364 368
365 // On Windows 10+, removes the default browser callback and stops the timer. 369 // On Windows 10+, removes the default browser callback and stops the timer.
(...skipping 11 matching lines...) Expand all
377 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); 381 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker);
378 }; 382 };
379 383
380 // Worker for checking and setting the default client application 384 // Worker for checking and setting the default client application
381 // for a given protocol. A different worker instance is needed for each 385 // 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 386 // protocol you are interested in, so to check or set the default for
383 // multiple protocols you should use multiple worker objects. 387 // multiple protocols you should use multiple worker objects.
384 class DefaultProtocolClientWorker : public DefaultWebClientWorker { 388 class DefaultProtocolClientWorker : public DefaultWebClientWorker {
385 public: 389 public:
386 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, 390 DefaultProtocolClientWorker(DefaultWebClientObserver* observer,
387 const std::string& protocol); 391 const std::string& protocol,
392 bool delete_observer,
393 bool interactive_permitted);
388 394
389 const std::string& protocol() const { return protocol_; } 395 const std::string& protocol() const { return protocol_; }
390 396
391 protected: 397 protected:
392 ~DefaultProtocolClientWorker() override; 398 ~DefaultProtocolClientWorker() override;
393 399
394 private: 400 private:
395 // Check is Chrome is the default handler for this protocol. 401 // Check is Chrome is the default handler for this protocol.
396 void CheckIsDefault() override; 402 void CheckIsDefault() override;
397 403
398 // Set Chrome as the default handler for this protocol. 404 // Set Chrome as the default handler for this protocol.
399 void SetAsDefault(bool interactive_permitted) override; 405 void SetAsDefault() override;
400 406
401 // Returns the histogram prefix for DefaultProtocolClientWorker. 407 // Returns the histogram prefix for DefaultProtocolClientWorker.
402 const char* GetHistogramPrefix() override; 408 const char* GetHistogramPrefix() override;
403 409
404 std::string protocol_; 410 std::string protocol_;
405 411
406 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); 412 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker);
407 }; 413 };
408 }; 414 };
409 415
410 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ 416 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698