summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/sync_global_error.cc
blob: c55e05b72196bf81fb6061ce322f8a031422268b (plain)
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
111
112
113
114
115
116
// Copyright (c) 2011 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/sync/sync_global_error.h"

#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_observer.h"
#include "chrome/browser/sync/sync_ui_util.h"
#include "chrome/browser/ui/global_error_service.h"
#include "chrome/browser/ui/global_error_service_factory.h"
#include "chrome/common/net/gaia/google_service_auth_error.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"

typedef GoogleServiceAuthError AuthError;

SyncGlobalError::SyncGlobalError(ProfileSyncService* service)
    : service_(service) {
  OnStateChanged();
}

SyncGlobalError::~SyncGlobalError() {
}

bool SyncGlobalError::HasBadge() {
  return !menu_label_.empty();
}

bool SyncGlobalError::HasMenuItem() {
  // When we're on Chrome OS we need to add a separate menu item to the wrench
  // menu to the show the error. On other platforms we can just reuse the
  // "Sign in to Chrome..." menu item to show the error.
#if defined(OS_CHROMEOS)
  return !menu_label_.empty();
#else
  return false;
#endif
}

int SyncGlobalError::MenuItemCommandID() {
  return IDC_SHOW_SYNC_ERROR;
}

string16 SyncGlobalError::MenuItemLabel() {
  return menu_label_;
}

void SyncGlobalError::ExecuteMenuItem(Browser* browser) {
  service_->ShowErrorUI();
}

bool SyncGlobalError::HasBubbleView() {
  return !bubble_message_.empty() && !bubble_accept_label_.empty();
}

string16 SyncGlobalError::GetBubbleViewTitle() {
  return l10n_util::GetStringUTF16(IDS_SYNC_ERROR_BUBBLE_VIEW_TITLE);
}

string16 SyncGlobalError::GetBubbleViewMessage() {
  return bubble_message_;
}

string16 SyncGlobalError::GetBubbleViewAcceptButtonLabel() {
  return bubble_accept_label_;
}

string16 SyncGlobalError::GetBubbleViewCancelButtonLabel() {
  return string16();
}

void SyncGlobalError::BubbleViewDidClose() {
}

void SyncGlobalError::BubbleViewAcceptButtonPressed() {
  service_->ShowErrorUI();
}

void SyncGlobalError::BubbleViewCancelButtonPressed() {
  NOTREACHED();
}

void SyncGlobalError::OnStateChanged() {
  string16 menu_label;
  string16 bubble_message;
  string16 bubble_accept_label;
  sync_ui_util::GetStatusLabelsForSyncGlobalError(
      service_, &menu_label, &bubble_message, &bubble_accept_label);

  // All the labels should be empty or all of them non-empty.
  DCHECK((menu_label.empty() && bubble_message.empty() &&
          bubble_accept_label.empty()) ||
         (!menu_label.empty() && !bubble_message.empty() &&
          !bubble_accept_label.empty()));

  if (menu_label != menu_label_ || bubble_message != bubble_message_ ||
      bubble_accept_label != bubble_accept_label_) {
    menu_label_ = menu_label;
    bubble_message_ = bubble_message;
    bubble_accept_label_ = bubble_accept_label;

    // Profile can be NULL during tests.
    Profile* profile = service_->profile();
    if (profile) {
      GlobalErrorServiceFactory::GetForProfile(
          profile)->NotifyErrorsChanged(this);
    }
  }
}

bool SyncGlobalError::HasCustomizedSyncMenuItem() {
  return !menu_label_.empty();
}