OLD | NEW |
---|---|
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 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 5 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 | 66 |
67 // Determine the day key (milliseconds since epoch for corresponding day in UTC) | 67 // Determine the day key (milliseconds since epoch for corresponding day in UTC) |
68 // for a given |timestamp|. | 68 // for a given |timestamp|. |
69 int64 TimestampToDayKey(Time timestamp) { | 69 int64 TimestampToDayKey(Time timestamp) { |
70 Time::Exploded exploded; | 70 Time::Exploded exploded; |
71 timestamp.LocalMidnight().LocalExplode(&exploded); | 71 timestamp.LocalMidnight().LocalExplode(&exploded); |
72 return (Time::FromUTCExploded(exploded) - Time::UnixEpoch()).InMilliseconds(); | 72 return (Time::FromUTCExploded(exploded) - Time::UnixEpoch()).InMilliseconds(); |
73 } | 73 } |
74 | 74 |
75 // Maximum number of users to report. | 75 // Maximum number of users to report. |
76 const int kMaxUserCount = 5; | 76 const int kMaxUserCount = 500; |
77 | 77 |
78 } // namespace | 78 } // namespace |
79 | 79 |
80 namespace policy { | 80 namespace policy { |
81 | 81 |
82 DeviceStatusCollector::DeviceStatusCollector( | 82 DeviceStatusCollector::DeviceStatusCollector( |
83 PrefService* local_state, | 83 PrefService* local_state, |
84 chromeos::system::StatisticsProvider* provider, | 84 chromeos::system::StatisticsProvider* provider, |
85 LocationUpdateRequester* location_update_requester) | 85 LocationUpdateRequester* location_update_requester) |
86 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), | 86 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 if (!(*device)->meid().empty()) | 423 if (!(*device)->meid().empty()) |
424 interface->set_meid((*device)->meid()); | 424 interface->set_meid((*device)->meid()); |
425 if (!(*device)->imei().empty()) | 425 if (!(*device)->imei().empty()) |
426 interface->set_imei((*device)->imei()); | 426 interface->set_imei((*device)->imei()); |
427 } | 427 } |
428 } | 428 } |
429 | 429 |
430 void DeviceStatusCollector::GetUsers(em::DeviceStatusReportRequest* request) { | 430 void DeviceStatusCollector::GetUsers(em::DeviceStatusReportRequest* request) { |
431 policy::BrowserPolicyConnectorChromeOS* connector = | 431 policy::BrowserPolicyConnectorChromeOS* connector = |
432 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 432 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
433 bool found_managed_user = false; | |
434 const chromeos::UserList& users = chromeos::UserManager::Get()->GetUsers(); | 433 const chromeos::UserList& users = chromeos::UserManager::Get()->GetUsers(); |
435 chromeos::UserList::const_iterator user; | 434 chromeos::UserList::const_iterator user; |
436 for (user = users.begin(); user != users.end(); ++user) { | 435 for (user = users.begin(); user != users.end(); ++user) { |
437 // Only regular users are reported. | 436 // Only regular users are reported. |
438 if ((*user)->GetType() != chromeos::User::USER_TYPE_REGULAR) | 437 if ((*user)->GetType() != chromeos::User::USER_TYPE_REGULAR) |
439 continue; | 438 continue; |
440 | 439 |
441 em::DeviceUser* device_user = request->add_user(); | 440 em::DeviceUser* device_user = request->add_user(); |
442 const std::string& email = (*user)->email(); | 441 const std::string& email = (*user)->email(); |
443 if (connector->GetUserAffiliation(email) == USER_AFFILIATION_MANAGED) { | 442 if (connector->GetUserAffiliation(email) == USER_AFFILIATION_MANAGED) { |
444 device_user->set_type(em::DeviceUser::USER_TYPE_MANAGED); | 443 device_user->set_type(em::DeviceUser::USER_TYPE_MANAGED); |
445 device_user->set_email(email); | 444 device_user->set_email(email); |
446 found_managed_user = true; | |
447 } else { | 445 } else { |
448 device_user->set_type(em::DeviceUser::USER_TYPE_UNMANAGED); | 446 device_user->set_type(em::DeviceUser::USER_TYPE_UNMANAGED); |
449 // Do not report the email address of unmanaged users. | 447 // Do not report the email address of unmanaged users. |
450 } | 448 } |
451 | 449 |
452 // Add only kMaxUserCount entries, unless no managed users are found in the | 450 // Add only kMaxUserCount entries. |
453 // first kMaxUserCount users. In that case, continue until at least one | 451 if (request->user_size() >= kMaxUserCount) |
Joao da Silva
2014/07/07 09:43:23
500 is an extreme limit for this... why not just r
| |
454 // managed user is found. | |
455 if (request->user_size() >= kMaxUserCount && found_managed_user) | |
456 break; | 452 break; |
457 } | 453 } |
458 } | 454 } |
459 | 455 |
460 void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) { | 456 void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) { |
461 // TODO(mnissler): Remove once the old cloud policy stack is retired. The old | 457 // TODO(mnissler): Remove once the old cloud policy stack is retired. The old |
462 // stack doesn't support reporting successful submissions back to here, so | 458 // stack doesn't support reporting successful submissions back to here, so |
463 // just assume whatever ends up in |request| gets submitted successfully. | 459 // just assume whatever ends up in |request| gets submitted successfully. |
464 GetDeviceStatus(request); | 460 GetDeviceStatus(request); |
465 OnSubmittedSuccessfully(); | 461 OnSubmittedSuccessfully(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 location.SetDouble(kSpeed, position.speed); | 555 location.SetDouble(kSpeed, position.speed); |
560 location.SetString(kTimestamp, | 556 location.SetString(kTimestamp, |
561 base::Int64ToString(position.timestamp.ToInternalValue())); | 557 base::Int64ToString(position.timestamp.ToInternalValue())); |
562 local_state_->Set(prefs::kDeviceLocation, location); | 558 local_state_->Set(prefs::kDeviceLocation, location); |
563 } | 559 } |
564 | 560 |
565 ScheduleGeolocationUpdateRequest(); | 561 ScheduleGeolocationUpdateRequest(); |
566 } | 562 } |
567 | 563 |
568 } // namespace policy | 564 } // namespace policy |
OLD | NEW |