summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 23:54:26 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 23:54:26 +0000
commit7e365c3fb2e127d1838ec665ba16baad5bf9a36e (patch)
tree8090590597382442d10d8030916635249b07e10c /chrome
parent6de9070e8a48d7faf1d723c5fd40ed29222c7125 (diff)
downloadchromium_src-7e365c3fb2e127d1838ec665ba16baad5bf9a36e.zip
chromium_src-7e365c3fb2e127d1838ec665ba16baad5bf9a36e.tar.gz
chromium_src-7e365c3fb2e127d1838ec665ba16baad5bf9a36e.tar.bz2
cros: Show system notification for GData upload/download.
BUG=chromium-os:27875 TEST=unit_tests --gtest_filter='*FileBrowser*' TEST=manual test uploading/downloading in GData Review URL: https://chromiumcodereview.appspot.com/9747001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd17
-rw-r--r--chrome/app/theme/notification_gdata.pngbin0 -> 407 bytes
-rw-r--r--chrome/app/theme/theme_resources.grd1
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_event_router.cc37
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_event_router.h8
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_notifications.cc79
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_notifications.h8
-rw-r--r--chrome/browser/chromeos/extensions/file_browser_notifications_unittest.cc69
-rw-r--r--chrome/browser/chromeos/gdata/gdata_operation_registry.cc30
-rw-r--r--chrome/browser/chromeos/gdata/gdata_operation_registry.h2
10 files changed, 231 insertions, 20 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 8a63cc3..5ee6a90 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -14160,6 +14160,23 @@ Battery full
Aw, Snap! There've been some errors while formatting...
</message>
+ <!-- ChromeOS GData synchronization notifications -->
+ <message name="IDS_CHROMEOS_GDATA_SYNC_TITLE" desc="Title text of notification message which is shown when gdata sync is on progress.">
+ Syncing
+ </message>
+ <message name="IDS_CHROMEOS_GDATA_SYNC_FINISHED_FAILURE_TITLE" desc="Title text of notification message which is shown when there are some errors while gdata sync.">
+ Could not sync
+ </message>
+ <message name="IDS_CHROMEOS_GDATA_SYNC_PROGRESS_MESSAGE" desc="Text of notification message which is shown when gdata file sync is on progress.">
+ Syncing <ph name="COUNT">$1<ex>3</ex></ph> files...
+ </message>
+ <message name="IDS_CHROMEOS_GDATA_SYNC_FINISHED_SUCCESS_MESSAGE" desc="Text of notification message which is shown when gdata sync finishes without any errors.">
+ Sync complete.
+ </message>
+ <message name="IDS_CHROMEOS_GDATA_SYNC_FINISHED_FAILURE_MESSAGE" desc="Text of notification message which is shown when there are some errors while gdata sync.">
+ Unable to connect.
+ </message>
+
<!-- Network state strings for ChromeOS -->
<message name="IDS_CHROMEOS_NETWORK_STATE_UNKNOWN" desc="Network state in about:network: UNKNOWN">
Unknown
diff --git a/chrome/app/theme/notification_gdata.png b/chrome/app/theme/notification_gdata.png
new file mode 100644
index 0000000..7eafb50
--- /dev/null
+++ b/chrome/app/theme/notification_gdata.png
Binary files differ
diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd
index ac029d2..741d754 100644
--- a/chrome/app/theme/theme_resources.grd
+++ b/chrome/app/theme/theme_resources.grd
@@ -464,6 +464,7 @@
<include name="IDR_NOTIFICATION_3G" file="notification_3g.png" type="BINDATA" />
<include name="IDR_NOTIFICATION_BARS_EMPTY" file="notification_bars_empty.png" type="BINDATA" />
<include name="IDR_NOTIFICATION_BARS_CRITICAL" file="notification_bars_critical.png" type="BINDATA" />
+ <include name="IDR_NOTIFICATION_GDATA" file="notification_gdata.png" type="BINDATA" />
<include name="IDR_NOTIFICATION_LOCALE_CHANGE" file="notification_locale_change.png" type="BINDATA" />
<include name="IDR_NOTIFICATION_LOW_BATTERY" file="notification_battery_low.png" type="BINDATA" />
<include name="IDR_NOTIFICATION_MENU" file="notification_menu.png" type="BINDATA" />
diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.cc b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
index 5725cd3..ec1014b 100644
--- a/chrome/browser/chromeos/extensions/file_browser_event_router.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_event_router.cc
@@ -82,7 +82,8 @@ FileBrowserEventRouter::FileBrowserEventRouter(
Profile* profile)
: delegate_(new FileBrowserEventRouter::FileWatcherDelegate(this)),
notifications_(new FileBrowserNotifications(profile)),
- profile_(profile) {
+ profile_(profile),
+ current_gdata_operation_failed_(false) {
}
FileBrowserEventRouter::~FileBrowserEventRouter() {
@@ -226,6 +227,12 @@ void FileBrowserEventRouter::MountCompleted(
void FileBrowserEventRouter::OnProgressUpdate(
const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) {
+ HandleProgressUpdateForExtensionAPI(list);
+ HandleProgressUpdateForSystemNotification(list);
+}
+
+void FileBrowserEventRouter::HandleProgressUpdateForExtensionAPI(
+ const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) {
scoped_ptr<ListValue> event_list(
file_manager_util::ProgressStatusVectorToListValue(
profile_,
@@ -242,6 +249,34 @@ void FileBrowserEventRouter::OnProgressUpdate(
NULL, GURL());
}
+void FileBrowserEventRouter::HandleProgressUpdateForSystemNotification(
+ const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) {
+ int active_operation_count = 0;
+ for (std::vector<
+ gdata::GDataOperationRegistry::ProgressStatus>::const_iterator iter =
+ list.begin();
+ iter != list.end(); ++iter) {
+ switch (iter->transfer_state) {
+ case gdata::GDataOperationRegistry::OPERATION_FAILED:
+ current_gdata_operation_failed_ = true;
+ break;
+ case gdata::GDataOperationRegistry::OPERATION_COMPLETED:
+ break;
+ default:
+ active_operation_count += 1;
+ break;
+ }
+ }
+
+ if (active_operation_count == 0) {
+ notifications_->ManageNotificationOnGDataSyncFinish(
+ !current_gdata_operation_failed_);
+ current_gdata_operation_failed_ = false;
+ } else {
+ notifications_->ManageNotificationOnGDataSyncProgress(
+ active_operation_count);
+ }
+}
void FileBrowserEventRouter::HandleFileWatchNotification(
const FilePath& local_path, bool got_error) {
diff --git a/chrome/browser/chromeos/extensions/file_browser_event_router.h b/chrome/browser/chromeos/extensions/file_browser_event_router.h
index 8b606f0..4ccdc8c 100644
--- a/chrome/browser/chromeos/extensions/file_browser_event_router.h
+++ b/chrome/browser/chromeos/extensions/file_browser_event_router.h
@@ -150,12 +150,20 @@ class FileBrowserEventRouter
const std::string& device_path,
bool small);
+ // Process GData operation list updates.
+ void HandleProgressUpdateForExtensionAPI(
+ const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list);
+ void HandleProgressUpdateForSystemNotification(
+ const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list);
+
scoped_refptr<FileWatcherDelegate> delegate_;
WatcherMap file_watchers_;
scoped_ptr<FileBrowserNotifications> notifications_;
Profile* profile_;
base::Lock lock_;
+ bool current_gdata_operation_failed_;
+
DISALLOW_COPY_AND_ASSIGN(FileBrowserEventRouter);
};
diff --git a/chrome/browser/chromeos/extensions/file_browser_notifications.cc b/chrome/browser/chromeos/extensions/file_browser_notifications.cc
index 38ea6ad..9cacf66 100644
--- a/chrome/browser/chromeos/extensions/file_browser_notifications.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_notifications.cc
@@ -117,6 +117,26 @@ void FileBrowserNotifications::ShowNotification(NotificationType type,
l10n_util::GetStringUTF16(GetMessageId(type)));
}
+void FileBrowserNotifications::ManageNotificationOnGDataSyncProgress(
+ int count) {
+ HideNotification(GDATA_SYNC_SUCCESS, "");
+ HideNotification(GDATA_SYNC_FAIL, "");
+ ShowNotificationWithMessage(GDATA_SYNC, "",
+ l10n_util::GetStringFUTF16Int(GetMessageId(GDATA_SYNC), count));
+}
+
+void FileBrowserNotifications::ManageNotificationOnGDataSyncFinish(
+ bool success) {
+ HideNotification(GDATA_SYNC, "");
+ if (success) {
+ HideNotification(FileBrowserNotifications::GDATA_SYNC_FAIL, "");
+ ShowNotification(FileBrowserNotifications::GDATA_SYNC_SUCCESS, "");
+ } else {
+ HideNotification(FileBrowserNotifications::GDATA_SYNC_SUCCESS, "");
+ ShowNotification(FileBrowserNotifications::GDATA_SYNC_FAIL, "");
+ }
+}
+
void FileBrowserNotifications::ShowNotificationWithMessage(
NotificationType type, const std::string& path, const string16& message) {
std::string notification_id;
@@ -239,6 +259,15 @@ void FileBrowserNotifications::CreateNotificationId(NotificationType type,
case(FORMAT_START):
*id = "FS";
break;
+ case(GDATA_SYNC):
+ *id = "GD";
+ break;
+ case(GDATA_SYNC_SUCCESS):
+ *id = "GS";
+ break;
+ case(GDATA_SYNC_FAIL):
+ *id = "GF";
+ break;
default:
*id = "FF";
}
@@ -253,20 +282,44 @@ void FileBrowserNotifications::CreateNotificationId(NotificationType type,
}
int FileBrowserNotifications::GetIconId(NotificationType type) {
- if (type == DEVICE || type == FORMAT_SUCCESS || type == FORMAT_START) {
- return IDR_PAGEINFO_INFO;
- } else {
- return IDR_PAGEINFO_WARNING_MAJOR;
+ switch (type) {
+ case(DEVICE):
+ case(FORMAT_SUCCESS):
+ case(FORMAT_START):
+ return IDR_PAGEINFO_INFO;
+ case(GDATA_SYNC):
+ case(GDATA_SYNC_SUCCESS):
+ case(GDATA_SYNC_FAIL):
+ return IDR_NOTIFICATION_GDATA;
+ case(DEVICE_FAIL):
+ case(FORMAT_START_FAIL):
+ case(FORMAT_FAIL):
+ return IDR_PAGEINFO_WARNING_MAJOR;
+ default:
+ NOTREACHED();
+ return 0;
}
}
int FileBrowserNotifications::GetTitleId(NotificationType type) {
- if (type == DEVICE || type == DEVICE_FAIL) {
- return IDS_REMOVABLE_DEVICE_DETECTION_TITLE;
- } else if (type == FORMAT_START) {
- return IDS_FORMATTING_OF_DEVICE_PENDING_TITLE;
- } else {
- return IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE;
+ switch (type) {
+ case(DEVICE):
+ case(DEVICE_FAIL):
+ return IDS_REMOVABLE_DEVICE_DETECTION_TITLE;
+ case(FORMAT_START):
+ return IDS_FORMATTING_OF_DEVICE_PENDING_TITLE;
+ case(FORMAT_START_FAIL):
+ case(FORMAT_SUCCESS):
+ case(FORMAT_FAIL):
+ return IDS_FORMATTING_OF_DEVICE_FINISHED_TITLE;
+ case(GDATA_SYNC):
+ case(GDATA_SYNC_SUCCESS):
+ return IDS_CHROMEOS_GDATA_SYNC_TITLE;
+ case(GDATA_SYNC_FAIL):
+ return IDS_CHROMEOS_GDATA_SYNC_FINISHED_FAILURE_TITLE;
+ default:
+ NOTREACHED();
+ return 0;
}
}
@@ -284,6 +337,12 @@ int FileBrowserNotifications::GetMessageId(NotificationType type) {
return IDS_FORMATTING_OF_DEVICE_PENDING_MESSAGE;
case(FORMAT_START_FAIL):
return IDS_FORMATTING_STARTED_FAILURE_MESSAGE;
+ case(GDATA_SYNC):
+ return IDS_CHROMEOS_GDATA_SYNC_PROGRESS_MESSAGE;
+ case(GDATA_SYNC_SUCCESS):
+ return IDS_CHROMEOS_GDATA_SYNC_FINISHED_SUCCESS_MESSAGE;
+ case(GDATA_SYNC_FAIL):
+ return IDS_CHROMEOS_GDATA_SYNC_FINISHED_FAILURE_MESSAGE;
default:
NOTREACHED();
return 0;
diff --git a/chrome/browser/chromeos/extensions/file_browser_notifications.h b/chrome/browser/chromeos/extensions/file_browser_notifications.h
index 96d943e..2522f4f 100644
--- a/chrome/browser/chromeos/extensions/file_browser_notifications.h
+++ b/chrome/browser/chromeos/extensions/file_browser_notifications.h
@@ -25,7 +25,10 @@ class FileBrowserNotifications
FORMAT_SUCCESS,
FORMAT_FAIL,
FORMAT_START,
- FORMAT_START_FAIL
+ FORMAT_START_FAIL,
+ GDATA_SYNC,
+ GDATA_SYNC_SUCCESS,
+ GDATA_SYNC_FAIL,
};
typedef std::map<std::string, linked_ptr<chromeos::SystemNotification> >
@@ -43,6 +46,9 @@ class FileBrowserNotifications
bool success,
bool is_unsupported);
+ void ManageNotificationOnGDataSyncProgress(int count);
+ void ManageNotificationOnGDataSyncFinish(bool success);
+
void ShowNotification(NotificationType type, const std::string& path);
void ShowNotificationDelayed(NotificationType type,
const std::string& path,
diff --git a/chrome/browser/chromeos/extensions/file_browser_notifications_unittest.cc b/chrome/browser/chromeos/extensions/file_browser_notifications_unittest.cc
index cbfce34..dfb88a9 100644
--- a/chrome/browser/chromeos/extensions/file_browser_notifications_unittest.cc
+++ b/chrome/browser/chromeos/extensions/file_browser_notifications_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -16,6 +16,7 @@ using ::testing::_;
using ::testing::InSequence;
using ::testing::Return;
using ::testing::StrEq;
+using ::testing::AnyNumber;
namespace chromeos {
@@ -217,4 +218,70 @@ TEST(FileBrowserMountNotificationsTest, MulitpleFail) {
device_label, false, false, false);
}
+TEST(FileBrowserGDataNotificationsTest, GDataSyncSuccess) {
+ MockFileBrowserNotificationsOnMount* mocked_notifications =
+ new MockFileBrowserNotificationsOnMount(NULL);
+ scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications);
+
+ EXPECT_CALL(*mocked_notifications, HideNotification(
+ FileBrowserNotifications::GDATA_SYNC, _)).Times(AnyNumber());
+ EXPECT_CALL(*mocked_notifications, HideNotification(
+ FileBrowserNotifications::GDATA_SYNC_SUCCESS, _)).Times(AnyNumber());
+ EXPECT_CALL(*mocked_notifications, HideNotification(
+ FileBrowserNotifications::GDATA_SYNC_FAIL, _)).Times(AnyNumber());
+ {
+ InSequence s;
+ EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage(
+ FileBrowserNotifications::GDATA_SYNC, _,
+ String16Equals(IDS_CHROMEOS_GDATA_SYNC_PROGRESS_MESSAGE, "2")));
+ EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage(
+ FileBrowserNotifications::GDATA_SYNC, _,
+ String16Equals(IDS_CHROMEOS_GDATA_SYNC_PROGRESS_MESSAGE, "1")));
+ EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage(
+ FileBrowserNotifications::GDATA_SYNC_SUCCESS, _,
+ l10n_util::GetStringUTF16(
+ IDS_CHROMEOS_GDATA_SYNC_FINISHED_SUCCESS_MESSAGE)));
+ }
+
+ notifications->ManageNotificationOnGDataSyncProgress(2);
+ notifications->ManageNotificationOnGDataSyncProgress(1);
+ notifications->ManageNotificationOnGDataSyncFinish(true);
+};
+
+
+TEST(FileBrowserGDataNotificationsTest, GDataSyncFailAndSuccess) {
+ MockFileBrowserNotificationsOnMount* mocked_notifications =
+ new MockFileBrowserNotificationsOnMount(NULL);
+ scoped_ptr<FileBrowserNotifications> notifications(mocked_notifications);
+
+ EXPECT_CALL(*mocked_notifications, HideNotification(
+ FileBrowserNotifications::GDATA_SYNC, _)).Times(AnyNumber());
+ EXPECT_CALL(*mocked_notifications, HideNotification(
+ FileBrowserNotifications::GDATA_SYNC_SUCCESS, _)).Times(AnyNumber());
+ EXPECT_CALL(*mocked_notifications, HideNotification(
+ FileBrowserNotifications::GDATA_SYNC_FAIL, _)).Times(AnyNumber());
+ {
+ InSequence s;
+ EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage(
+ FileBrowserNotifications::GDATA_SYNC, _,
+ String16Equals(IDS_CHROMEOS_GDATA_SYNC_PROGRESS_MESSAGE, "5")));
+ EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage(
+ FileBrowserNotifications::GDATA_SYNC_FAIL, _,
+ l10n_util::GetStringUTF16(
+ IDS_CHROMEOS_GDATA_SYNC_FINISHED_FAILURE_MESSAGE)));
+ EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage(
+ FileBrowserNotifications::GDATA_SYNC, _,
+ String16Equals(IDS_CHROMEOS_GDATA_SYNC_PROGRESS_MESSAGE, "2")));
+ EXPECT_CALL(*mocked_notifications, ShowNotificationWithMessage(
+ FileBrowserNotifications::GDATA_SYNC_SUCCESS, _,
+ l10n_util::GetStringUTF16(
+ IDS_CHROMEOS_GDATA_SYNC_FINISHED_SUCCESS_MESSAGE)));
+ }
+
+ notifications->ManageNotificationOnGDataSyncProgress(5);
+ notifications->ManageNotificationOnGDataSyncFinish(false);
+ notifications->ManageNotificationOnGDataSyncProgress(2);
+ notifications->ManageNotificationOnGDataSyncFinish(true);
+};
+
} // namespace chromeos.
diff --git a/chrome/browser/chromeos/gdata/gdata_operation_registry.cc b/chrome/browser/chromeos/gdata/gdata_operation_registry.cc
index c993a38..dc4f393 100644
--- a/chrome/browser/chromeos/gdata/gdata_operation_registry.cc
+++ b/chrome/browser/chromeos/gdata/gdata_operation_registry.cc
@@ -159,8 +159,10 @@ void GDataOperationRegistry::OnOperationStart(
*id = in_flight_operations_.Add(operation);
DVLOG(1) << "GDataOperation[" << *id << "] started.";
- FOR_EACH_OBSERVER(Observer, observer_list_,
- OnProgressUpdate(GetProgressStatusList()));
+ if (IsFileTransferOperation(operation)) {
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnProgressUpdate(GetProgressStatusList()));
+ }
}
void GDataOperationRegistry::OnOperationProgress(OperationID id) {
@@ -171,19 +173,32 @@ void GDataOperationRegistry::OnOperationProgress(OperationID id) {
DVLOG(1) << "GDataOperation[" << id << "] " <<
operation->progress_status().ToString();
- FOR_EACH_OBSERVER(Observer, observer_list_,
- OnProgressUpdate(GetProgressStatusList()));
+ if (IsFileTransferOperation(operation)) {
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnProgressUpdate(GetProgressStatusList()));
+ }
}
void GDataOperationRegistry::OnOperationFinish(OperationID id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ Operation* operation = in_flight_operations_.Lookup(id);
+ DCHECK(operation);
+
DVLOG(1) << "GDataOperation[" << id << "] finished.";
- FOR_EACH_OBSERVER(Observer, observer_list_,
- OnProgressUpdate(GetProgressStatusList()));
+ if (IsFileTransferOperation(operation)) {
+ FOR_EACH_OBSERVER(Observer, observer_list_,
+ OnProgressUpdate(GetProgressStatusList()));
+ }
in_flight_operations_.Remove(id);
}
+bool GDataOperationRegistry::IsFileTransferOperation(
+ const Operation* operation) const {
+ OperationType type = operation->progress_status().operation_type;
+ return type == OPERATION_UPLOAD || type == OPERATION_DOWNLOAD;
+}
+
std::vector<GDataOperationRegistry::ProgressStatus>
GDataOperationRegistry::GetProgressStatusList() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -193,7 +208,8 @@ GDataOperationRegistry::GetProgressStatusList() {
!iter.IsAtEnd();
iter.Advance()) {
const Operation* operation = iter.GetCurrentValue();
- status_list.push_back(operation->progress_status());
+ if (IsFileTransferOperation(operation))
+ status_list.push_back(operation->progress_status());
}
return status_list;
}
diff --git a/chrome/browser/chromeos/gdata/gdata_operation_registry.h b/chrome/browser/chromeos/gdata/gdata_operation_registry.h
index ecce955..c91424a 100644
--- a/chrome/browser/chromeos/gdata/gdata_operation_registry.h
+++ b/chrome/browser/chromeos/gdata/gdata_operation_registry.h
@@ -132,6 +132,8 @@ class GDataOperationRegistry {
void OnOperationProgress(OperationID operation);
void OnOperationFinish(OperationID operation);
+ bool IsFileTransferOperation(const Operation* operation) const;
+
typedef IDMap<Operation, IDMapOwnPointer> OperationIDMap;
OperationIDMap in_flight_operations_;
ObserverList<Observer> observer_list_;