File: avatar_button_error_controller.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (110 lines) | stat: -rw-r--r-- 4,429 bytes parent folder | download
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
// Copyright 2016 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 "chrome/browser/ui/avatar_button_error_controller.h"

#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/common/profile_management_switches.h"

using syncer::SyncErrorController;

AvatarButtonErrorController::AvatarButtonErrorController(
    AvatarButtonErrorControllerDelegate* delegate,
    Profile* profile)
    : delegate_(delegate),
      avatar_signin_error_controller_(profile, this),
      avatar_sync_error_controller_(profile, this),
      has_signin_error_(avatar_signin_error_controller_.HasSigninError()),
      has_sync_error_(avatar_sync_error_controller_.HasSyncError()) {}

AvatarButtonErrorController::~AvatarButtonErrorController() {}

void AvatarButtonErrorController::UpdateSigninError(bool has_signin_error) {
  bool had_error = HasAvatarError();
  has_signin_error_ = has_signin_error;
  if (had_error != HasAvatarError())
    delegate_->OnAvatarErrorChanged();
}

void AvatarButtonErrorController::UpdateSyncError(bool has_sync_error) {
  bool had_error = HasAvatarError();
  has_sync_error_ = has_sync_error;
  if (had_error != HasAvatarError())
    delegate_->OnAvatarErrorChanged();
}

AvatarButtonErrorController::SigninErrorObserver::SigninErrorObserver(
    Profile* profile,
    AvatarButtonErrorController* avatar_button_error_controller)
    : profile_(profile),
      avatar_button_error_controller_(avatar_button_error_controller) {
  SigninErrorController* signin_error_controller =
      profiles::GetSigninErrorController(profile_);
  if (signin_error_controller)
    signin_error_controller->AddObserver(this);
}

AvatarButtonErrorController::SigninErrorObserver::~SigninErrorObserver() {
  SigninErrorController* signin_error_controller =
      profiles::GetSigninErrorController(profile_);
  if (signin_error_controller)
    signin_error_controller->RemoveObserver(this);
}

void AvatarButtonErrorController::SigninErrorObserver::OnErrorChanged() {
  avatar_button_error_controller_->UpdateSigninError(HasSigninError());
}

bool AvatarButtonErrorController::SigninErrorObserver::HasSigninError() {
  const SigninErrorController* signin_error_controller =
      profiles::GetSigninErrorController(profile_);
  return signin_error_controller && signin_error_controller->HasError();
}

AvatarButtonErrorController::SyncErrorObserver::SyncErrorObserver(
    Profile* profile,
    AvatarButtonErrorController* avatar_button_error_controller)
    : profile_(profile),
      avatar_button_error_controller_(avatar_button_error_controller) {
  SyncErrorController* sync_error_controller = GetSyncErrorControllerIfNeeded();
  if (sync_error_controller)
    sync_error_controller->AddObserver(this);
}

AvatarButtonErrorController::SyncErrorObserver::~SyncErrorObserver() {
  SyncErrorController* sync_error_controller = GetSyncErrorControllerIfNeeded();
  if (sync_error_controller)
    sync_error_controller->RemoveObserver(this);
}

void AvatarButtonErrorController::SyncErrorObserver::OnErrorChanged() {
  avatar_button_error_controller_->UpdateSyncError(HasSyncError());
}

bool AvatarButtonErrorController::SyncErrorObserver::HasSyncError() {
  browser_sync::ProfileSyncService* sync_service =
      ProfileSyncServiceFactory::GetForProfile(profile_);
  if (switches::IsMaterialDesignUserMenu() && sync_service) {
    SyncErrorController* sync_error_controller =
        sync_service->sync_error_controller();
    browser_sync::ProfileSyncService::Status status;
    sync_service->QueryDetailedSyncStatus(&status);
    return sync_service->HasUnrecoverableError() ||
           status.sync_protocol_error.action == syncer::UPGRADE_CLIENT ||
           (sync_error_controller && sync_error_controller->HasError());
  }
  return false;
}

SyncErrorController* AvatarButtonErrorController::SyncErrorObserver::
    GetSyncErrorControllerIfNeeded() {
  if (!switches::IsMaterialDesignUserMenu())
    return nullptr;
  browser_sync::ProfileSyncService* sync_service =
      ProfileSyncServiceFactory::GetForProfile(profile_);
  return sync_service ? sync_service->sync_error_controller() : nullptr;
}