Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft committed Sep 26, 2023
1 parent 6b7bb72 commit cefcc92
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/AppInstallerCommonCore/AppInstallerTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ namespace AppInstaller::Logging
m_executionStage = stage;
}

void TelemetryTraceLogger::SetUseSummary(bool useSummary) noexcept
{
m_useSummary = useSummary;
}

std::unique_ptr<TelemetryTraceLogger> TelemetryTraceLogger::CreateSubTraceLogger() const
{
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), !this->m_isInitialized);
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ namespace AppInstaller::Logging

void SetExecutionStage(uint32_t stage) noexcept;

void SetUseSummary(bool useSummary) noexcept;

std::unique_ptr<TelemetryTraceLogger> CreateSubTraceLogger() const;

// Logs the failure info.
Expand Down
11 changes: 6 additions & 5 deletions src/Microsoft.Management.Deployment/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ namespace winrt::Microsoft::Management::Deployment::implementation
return callerName;
}

bool ShouldDelayBackgroundUpdateByCaller()
bool IsBackgroundProcessForPolicy()
{
bool shouldDelayBackgroundUpdateInterval = false;
bool isBackgroundProcessForPolicy = false;
try
{
auto [hrGetCallerId, callerProcessId] = GetCallerProcessId();
Expand All @@ -157,14 +157,15 @@ namespace winrt::Microsoft::Management::Deployment::implementation
// OutOfProc case, we check for explorer.exe
auto callerNameWide = AppInstaller::Utility::ConvertToUTF16(GetCallerName());
auto processName = AppInstaller::Utility::ConvertToUTF8(std::filesystem::path{ callerNameWide }.filename().wstring());
if (::AppInstaller::Utility::CaseInsensitiveEquals("explorer.exe", processName))
if (::AppInstaller::Utility::CaseInsensitiveEquals("explorer.exe", processName) ||
::AppInstaller::Utility::CaseInsensitiveEquals("taskhostw.exe", processName))
{
shouldDelayBackgroundUpdateInterval = true;
isBackgroundProcessForPolicy = true;
}
}
}
CATCH_LOG();

return shouldDelayBackgroundUpdateInterval;
return isBackgroundProcessForPolicy;
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Management.Deployment/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ namespace winrt::Microsoft::Management::Deployment::implementation
std::pair<HRESULT, DWORD> GetCallerProcessId();
std::wstring TryGetCallerProcessInfo(DWORD callerProcessId);
std::string GetCallerName();
bool ShouldDelayBackgroundUpdateByCaller();
bool IsBackgroundProcessForPolicy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ namespace winrt::Microsoft::Management::Deployment::implementation
m_sourceReference = std::move(sourceReference);
m_packageCatalogBackgroundUpdateInterval = ::AppInstaller::Settings::User().Get<::AppInstaller::Settings::Setting::AutoUpdateTimeInMinutes>();

if (ShouldDelayBackgroundUpdateByCaller())
if (IsBackgroundProcessForPolicy())
{
static constexpr winrt::Windows::Foundation::TimeSpan s_PackageCatalogUpdateIntervalDelay_Base = 168h; //1 week

// Add a bit of randomness to the default interval time
std::default_random_engine randomEngine(std::random_device{}());
std::uniform_int_distribution<long long> distribution(0, 168);
std::uniform_int_distribution<long long> distribution(0, 604800);

m_packageCatalogBackgroundUpdateInterval = s_PackageCatalogUpdateIntervalDelay_Base + std::chrono::hours(distribution(randomEngine));
m_packageCatalogBackgroundUpdateInterval = s_PackageCatalogUpdateIntervalDelay_Base + std::chrono::seconds(distribution(randomEngine));
}
}
void PackageCatalogReference::Initialize(winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions options)
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.Management.Deployment/PackageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace winrt::Microsoft::Management::Deployment::implementation
auto previousThreadGlobals = m_threadGlobals.SetForCurrentThread();
// Immediately reset as we only want the thread globals for logging within this object.
previousThreadGlobals.reset();
// TODO: Disable summary until we log more and have meaningful summary to be sent in the future.
m_threadGlobals.GetTelemetryLogger().SetUseSummary(false);
m_threadGlobals.GetTelemetryLogger().SetCaller(GetCallerName());
m_threadGlobals.GetTelemetryLogger().LogStartup(true);
}
Expand Down

0 comments on commit cefcc92

Please sign in to comment.