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

Unified Diff: chrome/browser/sync/glue/session_model_associator.cc

Issue 7740055: Set user-visible machine names and devices types for synced sessions. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Split off platform-specific code to various util files, addressed comments Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/glue/session_model_associator.cc
diff --git a/chrome/browser/sync/glue/session_model_associator.cc b/chrome/browser/sync/glue/session_model_associator.cc
index ea4eee306bb0bbd0728373c23140fc6cdd5311fd..320a19db88f4e70e2acc8c30a31ebd222e254187 100644
--- a/chrome/browser/sync/glue/session_model_associator.cc
+++ b/chrome/browser/sync/glue/session_model_associator.cc
@@ -9,6 +9,7 @@
#include <utility>
#include "base/logging.h"
+#include "base/sys_info.h"
#include "base/tracked.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_service_factory.h"
@@ -26,6 +27,13 @@
#include "content/browser/tab_contents/navigation_entry.h"
#include "content/common/notification_details.h"
#include "content/common/notification_service.h"
+#if defined(OS_LINUX)
+#include "base/linux_util.h"
+#elif defined(OS_MACOSX)
+#include "base/mac/mac_util.h"
+#elif defined(OS_WIN)
+#include "base/win/win_util.h"
+#endif
namespace browser_sync {
@@ -38,6 +46,8 @@ static const char kNoSessionsFolderError[] =
static const int max_sync_navigation_count = 6;
} // namespace
+std::string SessionModelAssociator::current_machine_name_ = "";
+
SessionModelAssociator::SessionModelAssociator(ProfileSyncService* sync_service)
: tab_pool_(sync_service),
local_session_syncid_(sync_api::kInvalidId),
@@ -123,6 +133,18 @@ void SessionModelAssociator::ReassociateWindows(bool reload_tabs) {
sync_pb::SessionHeader* header_s = specifics.mutable_header();
SyncedSession* current_session =
synced_session_tracker_.GetSession(local_tag);
+ header_s->set_client_name(current_machine_name_);
+#if defined(OS_LINUX)
+ header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_LINUX);
+#elif defined(OS_MACOSX)
+ header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_MAC);
+#elif defined(OS_WIN)
+ header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN);
+#elif defined(OS_CHROMEOS)
+ header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_CROS);
+#else
+ header_s->set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_OTHER);
+#endif
size_t window_num = 0;
std::set<SyncedWindowDelegate*> windows =
@@ -427,8 +449,10 @@ bool SessionModelAssociator::AssociateModels(SyncError* error) {
}
// Make sure we have a machine tag.
- if (current_machine_tag_.empty())
+ if (current_machine_tag_.empty()) {
InitializeCurrentMachineTag(&trans);
+ InitializeCurrentMachineName();
+ }
synced_session_tracker_.SetLocalSessionTag(current_machine_tag_);
if (!UpdateAssociationsFromSyncModel(root, &trans)) {
error->Reset(FROM_HERE,
@@ -466,6 +490,7 @@ bool SessionModelAssociator::DisassociateModels(SyncError* error) {
tab_map_.clear();
tab_pool_.clear();
local_session_syncid_ = sync_api::kInvalidId;
+ current_machine_tag_ = "";
// There is no local model stored with which to disassociate, just notify
// foreign session handlers.
@@ -484,8 +509,7 @@ void SessionModelAssociator::InitializeCurrentMachineTag(
// TODO(zea): We need a better way of creating a machine tag. The directory
// kernel's cache_guid changes every time syncing is turned on and off. This
// will result in session's associated with stale machine tags persisting on
- // the server since that tag will not be reused. Eventually this should
- // become some string identifiable to the user. (Home, Work, Laptop, etc.)
+ // the server since that tag will not be reused.
// See issue at http://crbug.com/59672
current_machine_tag_ = "session_sync";
current_machine_tag_.append(dir->cache_guid());
@@ -493,6 +517,23 @@ void SessionModelAssociator::InitializeCurrentMachineTag(
tab_pool_.set_machine_tag(current_machine_tag_);
}
+// Static
+void SessionModelAssociator::InitializeCurrentMachineName() {
+#if defined(OS_LINUX)
+ current_machine_name_ = base::GetLinuxDistro();
+#elif defined(OS_MACOSX)
+ current_machine_name_ = base::mac::GetHardwareModelName();
+#elif defined(OS_WIN)
+ current_machine_name_ = base::win::GetComputerName();
+#elif defined(OS_CHROMEOS)
+ current_machine_name_ = "Chromebook";
+#endif
+ if (current_machine_name_ == "Unknown" || current_machine_name_.empty()) {
+ current_machine_name_ = base::SysInfo::OperatingSystemName();
+ }
+}
+
+
bool SessionModelAssociator::UpdateAssociationsFromSyncModel(
const sync_api::ReadNode& root,
const sync_api::BaseTransaction* trans) {
@@ -561,6 +602,7 @@ bool SessionModelAssociator::AssociateForeignSpecifics(
synced_session_tracker_.GetSession(foreign_session_tag);
const sync_pb::SessionHeader& header = specifics.header();
+ PopulateSessionHeaderFromSpecifics(header, foreign_session);
foreign_session->windows.reserve(header.window_size());
VLOG(1) << "Associating " << foreign_session_tag << " with " <<
header.window_size() << " windows.";
@@ -605,6 +647,36 @@ void SessionModelAssociator::DisassociateForeignSession(
}
// Static
+void SessionModelAssociator::PopulateSessionHeaderFromSpecifics(
+ const sync_pb::SessionHeader& header_specifics,
+ SyncedSession* session_header) {
+ if (header_specifics.has_client_name()) {
+ session_header->client_name = header_specifics.client_name();
+ }
+ if (header_specifics.has_device_type()) {
+ switch (header_specifics.device_type()) {
+ case sync_pb::SessionHeader_DeviceType_TYPE_WIN:
+ session_header->device_type = SyncedSession::TYPE_WIN;
+ break;
+ case sync_pb::SessionHeader_DeviceType_TYPE_MAC:
+ session_header->device_type = SyncedSession::TYPE_MAC;
+ break;
+ case sync_pb::SessionHeader_DeviceType_TYPE_LINUX:
+ session_header->device_type = SyncedSession::TYPE_LINUX;
+ break;
+ case sync_pb::SessionHeader_DeviceType_TYPE_CROS:
+ session_header->device_type = SyncedSession::TYPE_CROS;
+ break;
+ case sync_pb::SessionHeader_DeviceType_TYPE_OTHER:
+ // Intentionally fall-through
+ default:
+ session_header->device_type = SyncedSession::TYPE_OTHER;
+ break;
+ }
+ }
+}
+
+// Static
void SessionModelAssociator::PopulateSessionWindowFromSpecifics(
const std::string& session_tag,
const sync_pb::SessionWindow& specifics,

Powered by Google App Engine
This is Rietveld 408576698